Skip to content

Commit

Permalink
issue 191: add padding data in AVPacket data
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed Apr 8, 2014
1 parent bf71736 commit e2a05cf
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/AVDemuxer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,20 @@ bool AVDemuxer::readFrame()
pkt->hasKeyFrame = !!(packet.flags & AV_PKT_FLAG_KEY);
// what about marking packet as invalid and do not use isCorrupt?
pkt->isCorrupt = !!(packet.flags & AV_PKT_FLAG_CORRUPT);
#if NO_PADDING_DATA
pkt->data = QByteArray((const char*)packet.data, packet.size);
#else
/*!
larger than the actual read bytes because some optimized bitstream readers read 32 or 64 bits at once and could read over the end.
The end of the input buffer avpkt->data should be set to 0 to ensure that no overreading happens for damaged MPEG streams
*/
QByteArray encoded;;
encoded.reserve(packet.size + FF_INPUT_BUFFER_PADDING_SIZE);
encoded.resize(packet.size);
// also copy padding data(usually 0)
memcpy(encoded.data(), packet.data, encoded.capacity());
pkt->data = encoded;
#endif //NO_PADDING_DATA
pkt->duration = packet.duration;
//if (packet.dts == AV_NOPTS_VALUE && )
if (packet.dts != AV_NOPTS_VALUE) //has B-frames
Expand Down
10 changes: 10 additions & 0 deletions src/AudioDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,19 @@ bool AudioDecoder::decode(const QByteArray &encoded)
return false;
DPTR_D(AudioDecoder);
AVPacket packet;
#if NO_PADDING_DATA
/*!
larger than the actual read bytes because some optimized bitstream readers read 32 or 64 bits at once and could read over the end.
The end of the input buffer avpkt->data should be set to 0 to ensure that no overreading happens for damaged MPEG streams
*/
// auto released by av_buffer_default_free
av_new_packet(&packet, encoded.size());
memcpy(packet.data, encoded.data(), encoded.size());
#else
av_init_packet(&packet);
packet.size = encoded.size();
packet.data = (uint8_t*)encoded.constData();
#endif //NO_PADDING_DATA
//TODO: use AVPacket directly instead of Packet?
int ret = avcodec_decode_audio4(d.codec_ctx, d.frame, &d.got_frame_ptr, &packet);
d.undecoded_size = qMin(encoded.size() - ret, encoded.size());
Expand Down
11 changes: 10 additions & 1 deletion src/VideoDecoderFFmpeg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,19 @@ bool VideoDecoderFFmpeg::decode(const QByteArray &encoded)
return false;
DPTR_D(VideoDecoderFFmpeg);
AVPacket packet;
#if NO_PADDING_DATA
/*!
larger than the actual read bytes because some optimized bitstream readers read 32 or 64 bits at once and could read over the end.
The end of the input buffer avpkt->data should be set to 0 to ensure that no overreading happens for damaged MPEG streams
*/
// auto released by av_buffer_default_free
av_new_packet(&packet, encoded.size());
memcpy(packet.data, encoded.data(), encoded.size());
#else
av_init_packet(&packet);
packet.size = encoded.size();
packet.data = (uint8_t*)encoded.constData();

#endif //NO_PADDING_DATA
//TODO: use AVPacket directly instead of Packet?
//AVStream *stream = format_context->streams[stream_idx];

Expand Down

0 comments on commit e2a05cf

Please sign in to comment.