Skip to content

Commit

Permalink
feat(afpacket): support isProtected api
Browse files Browse the repository at this point in the history
Signed-off-by: pingkai <pingkai010@gmail.com>
  • Loading branch information
pingkai committed Jun 4, 2020
1 parent 5983d82 commit a390893
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
8 changes: 4 additions & 4 deletions framework/base/media/AVAFPacket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,23 @@ void AVAFPacket::copyInfo()
mInfo.pos = mpkt->pos;
}

AVAFPacket::AVAFPacket(AVPacket &pkt)
AVAFPacket::AVAFPacket(AVPacket &pkt, bool isProtected) : mIsProtected(isProtected)
{
mpkt = av_packet_alloc();
av_init_packet(mpkt);
av_packet_ref(mpkt, &pkt);
copyInfo();
}

AVAFPacket::AVAFPacket(AVPacket *pkt)
AVAFPacket::AVAFPacket(AVPacket *pkt, bool isProtected) : mIsProtected(isProtected)
{
mpkt = av_packet_alloc();
av_init_packet(mpkt);
av_packet_ref(mpkt, pkt);
copyInfo();
}

AVAFPacket::AVAFPacket(AVPacket **pkt)
AVAFPacket::AVAFPacket(AVPacket **pkt, bool isProtected) : mIsProtected(isProtected)
{
mpkt = *pkt;
*pkt = nullptr;
Expand All @@ -66,7 +66,7 @@ uint8_t *AVAFPacket::getData()

unique_ptr<IAFPacket> AVAFPacket::clone()
{
return unique_ptr<IAFPacket>(new AVAFPacket(mpkt));
return unique_ptr<IAFPacket>(new AVAFPacket(mpkt, mIsProtected));
}

int64_t AVAFPacket::getSize()
Expand Down
12 changes: 9 additions & 3 deletions framework/base/media/AVAFPacket.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,23 @@ extern "C" {

class AVAFPacket : public IAFPacket {
public:
attribute_deprecated explicit AVAFPacket(AVPacket &pkt);
attribute_deprecated explicit AVAFPacket(AVPacket &pkt, bool isProtected = false);

explicit AVAFPacket(AVPacket *pkt);
explicit AVAFPacket(AVPacket *pkt, bool isProtected = false);

explicit AVAFPacket(AVPacket **pkt);
explicit AVAFPacket(AVPacket **pkt, bool isProtected = false);

~AVAFPacket() override;

void setDiscard(bool discard) override;

uint8_t *getData() override;

bool isProtected() override
{
return mIsProtected;
}

std::unique_ptr<IAFPacket> clone() override;

int64_t getSize() override;
Expand All @@ -36,6 +41,7 @@ class AVAFPacket : public IAFPacket {

private:
AVPacket *mpkt{nullptr};
bool mIsProtected;

void copyInfo();
};
Expand Down
5 changes: 5 additions & 0 deletions framework/base/media/IAFPacket.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ class CICADA_CPLUS_EXTERN IAFPacket {
return mbDiscard;
}

virtual bool isProtected()
{
return false;
}

packetInfo &getInfo();

void setExtraData(const uint8_t *extra_data, int extra_data_size)
Expand Down
2 changes: 1 addition & 1 deletion framework/demuxer/avFormatDemuxer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ namespace Cicada {
pkt->duration = av_rescale_q(pkt->duration, mCtx->streams[pkt->stream_index]->time_base, av_get_time_base_q());
}

packet = unique_ptr<IAFPacket>(new AVAFPacket(&pkt));
packet = unique_ptr<IAFPacket>(new AVAFPacket(&pkt, mSecretDemxuer));

if (needUpdateExtraData) {
packet->setExtraData(new_extradata, new_extradata_size);
Expand Down
1 change: 1 addition & 0 deletions framework/demuxer/avFormatDemuxer.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ namespace Cicada {
std::string mProbeString{};
AVFormatContext *mCtx = nullptr;
int MAX_QUEUE_SIZE = 60; // about 500ms video and audio packet
bool mSecretDemxuer{false};

private:
std::atomic_bool mInterrupted{false};
Expand Down

0 comments on commit a390893

Please sign in to comment.