lavf: allow BSFs to drop packets.

If pkt->size == 0 && pkt->side_data_elems == 0 after bsf->filter()
returns, the packet is considered dropped.
pull/187/head
Ronald S. Bultje 9 years ago
parent 867637caea
commit 6d8ab358a3
  1. 4
      doc/APIchanges
  2. 2
      ffmpeg.c
  3. 3
      libavcodec/avcodec.h
  4. 2
      libavcodec/version.h
  5. 4
      libavformat/avformat.h
  6. 24
      libavformat/mux.c
  7. 5
      libavformat/utils.c
  8. 2
      libavformat/version.h

@ -15,6 +15,10 @@ libavutil: 2015-08-28
API changes, most recent first: API changes, most recent first:
2016-03-11 - xxxxxxx - lavf/lavc 57.28.101
Add requirement to bitstream filtering API that returned packets with
size == 0 and side_data_elems == 0 are to be skipped by the caller.
2016-XX-XX - xxxxxxx - lavf 57.28.100 2016-XX-XX - xxxxxxx - lavf 57.28.100
Add protocol blacklisting API Add protocol blacklisting API

@ -694,6 +694,8 @@ static void write_frame(AVFormatContext *s, AVPacket *pkt, OutputStream *ost)
if (exit_on_error) if (exit_on_error)
exit_program(1); exit_program(1);
} }
if (pkt->size == 0 && pkt->side_data_elems == 0)
return;
if (!(s->oformat->flags & AVFMT_NOTIMESTAMPS)) { if (!(s->oformat->flags & AVFMT_NOTIMESTAMPS)) {
if (pkt->dts != AV_NOPTS_VALUE && if (pkt->dts != AV_NOPTS_VALUE &&

@ -5253,7 +5253,8 @@ AVBitStreamFilterContext *av_bitstream_filter_init(const char *name);
* If the return value is 0, the output buffer is not allocated and * If the return value is 0, the output buffer is not allocated and
* should be considered identical to the input buffer, or in case * should be considered identical to the input buffer, or in case
* *poutbuf was set it points to the input buffer (not necessarily to * *poutbuf was set it points to the input buffer (not necessarily to
* its starting address). * its starting address). A special case is if *poutbuf was set to NULL and
* *poutbuf_size was set to 0, which indicates the packet should be dropped.
*/ */
int av_bitstream_filter_filter(AVBitStreamFilterContext *bsfc, int av_bitstream_filter_filter(AVBitStreamFilterContext *bsfc,
AVCodecContext *avctx, const char *args, AVCodecContext *avctx, const char *args,

@ -29,7 +29,7 @@
#define LIBAVCODEC_VERSION_MAJOR 57 #define LIBAVCODEC_VERSION_MAJOR 57
#define LIBAVCODEC_VERSION_MINOR 28 #define LIBAVCODEC_VERSION_MINOR 28
#define LIBAVCODEC_VERSION_MICRO 100 #define LIBAVCODEC_VERSION_MICRO 101
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
LIBAVCODEC_VERSION_MINOR, \ LIBAVCODEC_VERSION_MINOR, \

@ -2850,7 +2850,9 @@ int avformat_queue_attached_pictures(AVFormatContext *s);
* Apply a list of bitstream filters to a packet. * Apply a list of bitstream filters to a packet.
* *
* @param codec AVCodecContext, usually from an AVStream * @param codec AVCodecContext, usually from an AVStream
* @param pkt the packet to apply filters to * @param pkt the packet to apply filters to. If, on success, the returned
* packet has size == 0 and side_data_elems == 0, it indicates that
* the packet should be dropped
* @param bsfc a NULL-terminated list of filters to apply * @param bsfc a NULL-terminated list of filters to apply
* @return >=0 on success; * @return >=0 on success;
* AVERROR code on failure * AVERROR code on failure

@ -1025,6 +1025,19 @@ int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt)
if (pkt) { if (pkt) {
AVStream *st = s->streams[pkt->stream_index]; AVStream *st = s->streams[pkt->stream_index];
if (s->oformat->check_bitstream) {
if (!st->internal->bitstream_checked) {
if ((ret = s->oformat->check_bitstream(s, pkt)) < 0)
goto fail;
else if (ret == 1)
st->internal->bitstream_checked = 1;
}
}
av_apply_bitstream_filters(st->codec, pkt, st->internal->bsfc);
if (pkt->size == 0 && pkt->side_data_elems == 0)
return 0;
if (s->debug & FF_FDEBUG_TS) if (s->debug & FF_FDEBUG_TS)
av_log(s, AV_LOG_TRACE, "av_interleaved_write_frame size:%d dts:%s pts:%s\n", av_log(s, AV_LOG_TRACE, "av_interleaved_write_frame size:%d dts:%s pts:%s\n",
pkt->size, av_ts2str(pkt->dts), av_ts2str(pkt->pts)); pkt->size, av_ts2str(pkt->dts), av_ts2str(pkt->pts));
@ -1038,17 +1051,6 @@ int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt)
ret = AVERROR(EINVAL); ret = AVERROR(EINVAL);
goto fail; goto fail;
} }
if (s->oformat->check_bitstream) {
if (!st->internal->bitstream_checked) {
if ((ret = s->oformat->check_bitstream(s, pkt)) < 0)
goto fail;
else if (ret == 1)
st->internal->bitstream_checked = 1;
}
}
av_apply_bitstream_filters(st->codec, pkt, st->internal->bsfc);
} else { } else {
av_log(s, AV_LOG_TRACE, "av_interleaved_write_frame FLUSH\n"); av_log(s, AV_LOG_TRACE, "av_interleaved_write_frame FLUSH\n");
flush = 1; flush = 1;

@ -4710,6 +4710,11 @@ int av_apply_bitstream_filters(AVCodecContext *codec, AVPacket *pkt,
&new_pkt.data, &new_pkt.size, &new_pkt.data, &new_pkt.size,
pkt->data, pkt->size, pkt->data, pkt->size,
pkt->flags & AV_PKT_FLAG_KEY); pkt->flags & AV_PKT_FLAG_KEY);
if (a == 0 && new_pkt.size == 0 && new_pkt.side_data_elems == 0) {
av_packet_unref(pkt);
memset(pkt, 0, sizeof(*pkt));
return 0;
}
if(a == 0 && new_pkt.data != pkt->data) { if(a == 0 && new_pkt.data != pkt->data) {
uint8_t *t = av_malloc(new_pkt.size + AV_INPUT_BUFFER_PADDING_SIZE); //the new should be a subset of the old so cannot overflow uint8_t *t = av_malloc(new_pkt.size + AV_INPUT_BUFFER_PADDING_SIZE); //the new should be a subset of the old so cannot overflow
if (t) { if (t) {

@ -31,7 +31,7 @@
#define LIBAVFORMAT_VERSION_MAJOR 57 #define LIBAVFORMAT_VERSION_MAJOR 57
#define LIBAVFORMAT_VERSION_MINOR 28 #define LIBAVFORMAT_VERSION_MINOR 28
#define LIBAVFORMAT_VERSION_MICRO 100 #define LIBAVFORMAT_VERSION_MICRO 101
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
LIBAVFORMAT_VERSION_MINOR, \ LIBAVFORMAT_VERSION_MINOR, \

Loading…
Cancel
Save