diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2011-12-22 00:48:38 +0100 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2011-12-22 01:51:53 +0100 |
commit | 52c522c72090233edeeb0486a9bd8bee925a710a (patch) | |
tree | 23f091bb1fb649e8358d01516670360c13cb08e6 /libavformat | |
parent | a40f43db647bfacafbd1e27a4cd5f6134c6e6c53 (diff) | |
parent | e9dc92012773aab5f51d8d37eb14564988c5f217 (diff) | |
download | ffmpeg-52c522c72090233edeeb0486a9bd8bee925a710a.tar.gz |
Merge remote-tracking branch 'qatar/master'
* qatar/master: (27 commits)
asfdec: add side data to ASFStream packet instead of output packet.
idroqdec: set AVFMTCTX_NOHEADER and create streams as they occur.
nellymoserdec: Indicate that the decoder can handle changed parameters
libavcodec: Apply parameter change side data when decoding audio
flvdec: Add param change side data if the sample rate or channels have changed
libavformat: Add a utility function for adding parameter change side data
libavcodec: Define a side data type for parameter changes
aacdec: Handle new extradata passed as side data
flvdec: Export new AAC/H.264 extradata as side data on the next packet
libavcodec: Define a side data type for new extradata
flacdec: skip all track indices at once instead of looping.
mxf: Add PictureEssenceCoding UL for V210.
mxfdec: consider QuantizationBits between 17 and 24 to be pcm_s24*
mxfenc: Add support for MPEG-2 MP@HL-14 in mxf container.
mxf: H.264/MPEG-4 AVC Intra support
configure: Show whether the safe bitstream reader is enabled
x86: Tighten register constraints for decode_significance*_x86.
Replace Subversion revisions in comments by Git hashes.
h264_cabac: synchronize decode_significance_*_x86 conditionals
w32threads: wait for the waked thread in pthread_cond_signal.
...
Conflicts:
libavcodec/avcodec.h
libavcodec/version.h
libavformat/flvdec.c
libavformat/utils.c
tests/ref/lavfi/pixdesc
tests/ref/lavfi/pixfmts_copy
tests/ref/lavfi/pixfmts_null
tests/ref/lavfi/pixfmts_scale
tests/ref/lavfi/pixfmts_vflip
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat')
-rw-r--r-- | libavformat/asfdec.c | 2 | ||||
-rw-r--r-- | libavformat/flacdec.c | 5 | ||||
-rw-r--r-- | libavformat/flv.h | 1 | ||||
-rw-r--r-- | libavformat/flvdec.c | 76 | ||||
-rw-r--r-- | libavformat/idroqdec.c | 27 | ||||
-rw-r--r-- | libavformat/internal.h | 8 | ||||
-rw-r--r-- | libavformat/network.c | 5 | ||||
-rw-r--r-- | libavformat/utils.c | 43 |
8 files changed, 139 insertions, 28 deletions
diff --git a/libavformat/asfdec.c b/libavformat/asfdec.c index 0bb210bcd6..5af112d334 100644 --- a/libavformat/asfdec.c +++ b/libavformat/asfdec.c @@ -987,7 +987,7 @@ static int ff_asf_parse_packet(AVFormatContext *s, AVIOContext *pb, AVPacket *pk asf_st->packet_pos= asf->packet_pos; if (asf_st->pkt.data && asf_st->palette_changed) { uint8_t *pal; - pal = av_packet_new_side_data(pkt, AV_PKT_DATA_PALETTE, + pal = av_packet_new_side_data(&asf_st->pkt, AV_PKT_DATA_PALETTE, AVPALETTE_SIZE); if (!pal) { av_log(s, AV_LOG_ERROR, "Cannot append palette to packet\n"); diff --git a/libavformat/flacdec.c b/libavformat/flacdec.c index 163d2fac61..070f9af3f6 100644 --- a/libavformat/flacdec.c +++ b/libavformat/flacdec.c @@ -102,7 +102,7 @@ static int flac_read_header(AVFormatContext *s, uint8_t isrc[13]; uint64_t start; const uint8_t *offset; - int i, j, chapters, track, ti; + int i, chapters, track, ti; if (metadata_size < 431) return AVERROR_INVALIDDATA; offset = buffer + 395; @@ -119,8 +119,7 @@ static int flac_read_header(AVFormatContext *s, offset += 14; ti = bytestream_get_byte(&offset); if (ti <= 0) return AVERROR_INVALIDDATA; - for (j = 0; j < ti; j++) - offset += 12; + offset += ti * 12; avpriv_new_chapter(s, track, st->time_base, start, AV_NOPTS_VALUE, isrc); } } else { diff --git a/libavformat/flv.h b/libavformat/flv.h index 2165357b6b..ef8eaabb44 100644 --- a/libavformat/flv.h +++ b/libavformat/flv.h @@ -66,6 +66,7 @@ enum { FLV_STREAM_TYPE_VIDEO, FLV_STREAM_TYPE_AUDIO, FLV_STREAM_TYPE_DATA, + FLV_STREAM_TYPE_NB, }; enum { diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c index 34945299b6..765eee5893 100644 --- a/libavformat/flvdec.c +++ b/libavformat/flvdec.c @@ -37,6 +37,10 @@ typedef struct { int wrong_dts; ///< wrong dts due to negative cts + uint8_t *new_extradata[FLV_STREAM_TYPE_NB]; + int new_extradata_size[FLV_STREAM_TYPE_NB]; + int last_sample_rate; + int last_channels; } FLVContext; static int flv_probe(AVProbeData *p) @@ -50,8 +54,7 @@ static int flv_probe(AVProbeData *p) return 0; } -static void flv_set_audio_codec(AVFormatContext *s, AVStream *astream, int flv_codecid) { - AVCodecContext *acodec = astream->codec; +static void flv_set_audio_codec(AVFormatContext *s, AVStream *astream, AVCodecContext *acodec, int flv_codecid) { switch(flv_codecid) { //no distinction between S16 and S8 PCM codec flags case FLV_CODECID_PCM: @@ -411,6 +414,15 @@ static int flv_read_header(AVFormatContext *s, return 0; } +static int flv_read_close(AVFormatContext *s) +{ + int i; + FLVContext *flv = s->priv_data; + for(i=0; i<FLV_STREAM_TYPE_NB; i++) + av_freep(&flv->new_extradata[i]); + return 0; +} + static int flv_get_extradata(AVFormatContext *s, AVStream *st, int size) { av_free(st->codec->extradata); @@ -422,6 +434,18 @@ static int flv_get_extradata(AVFormatContext *s, AVStream *st, int size) return 0; } +static int flv_queue_extradata(FLVContext *flv, AVIOContext *pb, int stream, + int size) +{ + av_free(flv->new_extradata[stream]); + flv->new_extradata[stream] = av_mallocz(size + FF_INPUT_BUFFER_PADDING_SIZE); + if (!flv->new_extradata[stream]) + return AVERROR(ENOMEM); + flv->new_extradata_size[stream] = size; + avio_read(pb, flv->new_extradata[stream], size); + return 0; +} + static int flv_read_packet(AVFormatContext *s, AVPacket *pkt) { FLVContext *flv = s->priv_data; @@ -429,6 +453,7 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt) int stream_type=-1; int64_t next, pos; int64_t dts, pts = AV_NOPTS_VALUE; + int sample_rate, channels; AVStream *st = NULL; for(;;avio_skip(s->pb, 4)){ /* pkt size is repeated at end. skip it */ @@ -518,13 +543,24 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt) } if(stream_type == FLV_STREAM_TYPE_AUDIO){ + int bits_per_coded_sample; + channels = (flags & FLV_AUDIO_CHANNEL_MASK) == FLV_STEREO ? 2 : 1; + sample_rate = (44100 << ((flags & FLV_AUDIO_SAMPLERATE_MASK) >> FLV_AUDIO_SAMPLERATE_OFFSET) >> 3); + bits_per_coded_sample = (flags & FLV_AUDIO_SAMPLESIZE_MASK) ? 16 : 8; if(!st->codec->channels || !st->codec->sample_rate || !st->codec->bits_per_coded_sample) { - st->codec->channels = (flags & FLV_AUDIO_CHANNEL_MASK) == FLV_STEREO ? 2 : 1; - st->codec->sample_rate = (44100 << ((flags & FLV_AUDIO_SAMPLERATE_MASK) >> FLV_AUDIO_SAMPLERATE_OFFSET) >> 3); - st->codec->bits_per_coded_sample = (flags & FLV_AUDIO_SAMPLESIZE_MASK) ? 16 : 8; + st->codec->channels = channels; + st->codec->sample_rate = sample_rate; + st->codec->bits_per_coded_sample = bits_per_coded_sample; } if(!st->codec->codec_id){ - flv_set_audio_codec(s, st, flags & FLV_AUDIO_CODECID_MASK); + flv_set_audio_codec(s, st, st->codec, flags & FLV_AUDIO_CODECID_MASK); + flv->last_sample_rate = st->codec->sample_rate; + flv->last_channels = st->codec->channels; + } else { + AVCodecContext ctx; + ctx.sample_rate = sample_rate; + flv_set_audio_codec(s, st, &ctx, flags & FLV_AUDIO_CODECID_MASK); + sample_rate = ctx.sample_rate; } } else if(stream_type == FLV_STREAM_TYPE_VIDEO) { size -= flv_set_video_codec(s, st, flags & FLV_VIDEO_CODECID_MASK); @@ -545,8 +581,13 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt) if (flv->wrong_dts) dts = AV_NOPTS_VALUE; } - - if (type == 0 && !st->codec->extradata) { + if (type == 0 && (!st->codec->extradata || st->codec->codec_id != CODEC_ID_H264)) { + if (st->codec->extradata) { + if ((ret = flv_queue_extradata(flv, s->pb, stream_type, size)) < 0) + return ret; + ret = AVERROR(EAGAIN); + goto leave; + } if ((ret = flv_get_extradata(s, st, size)) < 0) return ret; if (st->codec->codec_id == CODEC_ID_AAC) { @@ -583,8 +624,22 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt) pkt->dts = dts; pkt->pts = pts == AV_NOPTS_VALUE ? dts : pts; pkt->stream_index = st->index; - if(st->codec->codec_id == CODEC_ID_NELLYMOSER) - av_packet_new_side_data(pkt, 'F', 1)[0]= flags; + if (flv->new_extradata[stream_type]) { + uint8_t *side = av_packet_new_side_data(pkt, AV_PKT_DATA_NEW_EXTRADATA, + flv->new_extradata_size[stream_type]); + if (side) { + memcpy(side, flv->new_extradata[stream_type], + flv->new_extradata_size[stream_type]); + av_freep(&flv->new_extradata[stream_type]); + flv->new_extradata_size[stream_type] = 0; + } + } + if (stream_type == FLV_STREAM_TYPE_AUDIO && (sample_rate != flv->last_sample_rate || + channels != flv->last_channels)) { + flv->last_sample_rate = sample_rate; + flv->last_channels = channels; + ff_add_param_change(pkt, channels, 0, sample_rate, 0, 0); + } if ( stream_type == FLV_STREAM_TYPE_AUDIO || ((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_KEY) || @@ -640,6 +695,7 @@ AVInputFormat ff_flv_demuxer = { #if 0 .read_seek2 = flv_read_seek2, #endif + .read_close = flv_read_close, .extensions = "flv", .value = CODEC_ID_FLV1, }; diff --git a/libavformat/idroqdec.c b/libavformat/idroqdec.c index 9ac32eb668..fffee9d76e 100644 --- a/libavformat/idroqdec.c +++ b/libavformat/idroqdec.c @@ -45,6 +45,7 @@ typedef struct RoqDemuxContext { + int frame_rate; int width; int height; int audio_channels; @@ -71,29 +72,21 @@ static int roq_read_header(AVFormatContext *s, { RoqDemuxContext *roq = s->priv_data; AVIOContext *pb = s->pb; - int framerate; - AVStream *st; unsigned char preamble[RoQ_CHUNK_PREAMBLE_SIZE]; /* get the main header */ if (avio_read(pb, preamble, RoQ_CHUNK_PREAMBLE_SIZE) != RoQ_CHUNK_PREAMBLE_SIZE) return AVERROR(EIO); - framerate = AV_RL16(&preamble[6]); + roq->frame_rate = AV_RL16(&preamble[6]); /* init private context parameters */ roq->width = roq->height = roq->audio_channels = roq->video_pts = roq->audio_frame_count = 0; roq->audio_stream_index = -1; + roq->video_stream_index = -1; - st = avformat_new_stream(s, NULL); - if (!st) - return AVERROR(ENOMEM); - avpriv_set_pts_info(st, 63, 1, framerate); - roq->video_stream_index = st->index; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = CODEC_ID_ROQ; - st->codec->codec_tag = 0; /* no fourcc */ + s->ctx_flags |= AVFMTCTX_NOHEADER; return 0; } @@ -131,8 +124,16 @@ static int roq_read_packet(AVFormatContext *s, switch (chunk_type) { case RoQ_INFO: - if (!roq->width || !roq->height) { - AVStream *st = s->streams[roq->video_stream_index]; + if (roq->video_stream_index == -1) { + AVStream *st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + avpriv_set_pts_info(st, 63, 1, roq->frame_rate); + roq->video_stream_index = st->index; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + st->codec->codec_id = CODEC_ID_ROQ; + st->codec->codec_tag = 0; /* no fourcc */ + if (avio_read(pb, preamble, RoQ_CHUNK_PREAMBLE_SIZE) != RoQ_CHUNK_PREAMBLE_SIZE) return AVERROR(EIO); st->codec->width = roq->width = AV_RL16(preamble); diff --git a/libavformat/internal.h b/libavformat/internal.h index c3be0df380..c8376f7dda 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -298,4 +298,12 @@ int64_t ff_gen_search(AVFormatContext *s, int stream_index, void avpriv_set_pts_info(AVStream *s, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den); +/** + * Add side data to a packet for changing parameters to the given values. + * Parameters set to 0 aren't included in the change. + */ +int ff_add_param_change(AVPacket *pkt, int32_t channels, + uint64_t channel_layout, int32_t sample_rate, + int32_t width, int32_t height); + #endif /* AVFORMAT_INTERNAL_H */ diff --git a/libavformat/network.c b/libavformat/network.c index e27c64d3c0..9beaaaf350 100644 --- a/libavformat/network.c +++ b/libavformat/network.c @@ -124,13 +124,16 @@ int ff_network_inited_globally; int ff_network_init(void) { +#if HAVE_WINSOCK2_H + WSADATA wsaData; +#endif + if (!ff_network_inited_globally) av_log(NULL, AV_LOG_WARNING, "Using network protocols without global " "network initialization. Please use " "avformat_network_init(), this will " "become mandatory later.\n"); #if HAVE_WINSOCK2_H - WSADATA wsaData; if (WSAStartup(MAKEWORD(1,1), &wsaData)) return 0; #endif diff --git a/libavformat/utils.c b/libavformat/utils.c index edcae2fe37..65b1fe3c97 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -26,6 +26,7 @@ #include "internal.h" #include "libavcodec/internal.h" #include "libavcodec/raw.h" +#include "libavcodec/bytestream.h" #include "libavutil/opt.h" #include "libavutil/dict.h" #include "libavutil/pixdesc.h" @@ -4290,3 +4291,45 @@ int avformat_network_deinit(void) #endif return 0; } + +int ff_add_param_change(AVPacket *pkt, int32_t channels, + uint64_t channel_layout, int32_t sample_rate, + int32_t width, int32_t height) +{ + uint32_t flags = 0; + int size = 4; + uint8_t *data; + if (!pkt) + return AVERROR(EINVAL); + if (channels) { + size += 4; + flags |= AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT; + } + if (channel_layout) { + size += 8; + flags |= AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT; + } + if (sample_rate) { + size += 4; + flags |= AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE; + } + if (width || height) { + size += 8; + flags |= AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS; + } + data = av_packet_new_side_data(pkt, AV_PKT_DATA_PARAM_CHANGE, size); + if (!data) + return AVERROR(ENOMEM); + bytestream_put_le32(&data, flags); + if (channels) + bytestream_put_le32(&data, channels); + if (channel_layout) + bytestream_put_le64(&data, channel_layout); + if (sample_rate) + bytestream_put_le32(&data, sample_rate); + if (width || height) { + bytestream_put_le32(&data, width); + bytestream_put_le32(&data, height); + } + return 0; +} |