summaryrefslogtreecommitdiff
path: root/libavformat/rtpdec_xiph.c
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2014-06-18 20:42:52 +0200
committerAnton Khirnov <anton@khirnov.net>2016-02-23 17:01:58 +0100
commit9200514ad8717c63f82101dc394f4378854325bf (patch)
tree566b8d48565a88303363198acc81de06363daa7a /libavformat/rtpdec_xiph.c
parenta8068346e48e123f8d3bdf4d64464d81e53e5fc7 (diff)
lavf: replace AVStream.codec with AVStream.codecpar
Currently, AVStream contains an embedded AVCodecContext instance, which is used by demuxers to export stream parameters to the caller and by muxers to receive stream parameters from the caller. It is also used internally as the codec context that is passed to parsers. In addition, it is also widely used by the callers as the decoding (when demuxer) or encoding (when muxing) context, though this has been officially discouraged since Libav 11. There are multiple important problems with this approach: - the fields in AVCodecContext are in general one of * stream parameters * codec options * codec state However, it's not clear which ones are which. It is consequently unclear which fields are a demuxer allowed to set or a muxer allowed to read. This leads to erratic behaviour depending on whether decoding or encoding is being performed or not (and whether it uses the AVStream embedded codec context). - various synchronization issues arising from the fact that the same context is used by several different APIs (muxers/demuxers, parsers, bitstream filters and encoders/decoders) simultaneously, with there being no clear rules for who can modify what and the different processes being typically delayed with respect to each other. - avformat_find_stream_info() making it necessary to support opening and closing a single codec context multiple times, thus complicating the semantics of freeing various allocated objects in the codec context. Those problems are resolved by replacing the AVStream embedded codec context with a newly added AVCodecParameters instance, which stores only the stream parameters exported by the demuxers or read by the muxers.
Diffstat (limited to 'libavformat/rtpdec_xiph.c')
-rw-r--r--libavformat/rtpdec_xiph.c33
1 files changed, 17 insertions, 16 deletions
diff --git a/libavformat/rtpdec_xiph.c b/libavformat/rtpdec_xiph.c
index c79cfeb7b5..5ad6974703 100644
--- a/libavformat/rtpdec_xiph.c
+++ b/libavformat/rtpdec_xiph.c
@@ -222,16 +222,17 @@ static int get_base128(const uint8_t ** buf, const uint8_t * buf_end)
* Based off parse_packed_headers in Vorbis RTP
*/
static int
-parse_packed_headers(const uint8_t * packed_headers,
+parse_packed_headers(AVFormatContext *s,
+ const uint8_t * packed_headers,
const uint8_t * packed_headers_end,
- AVCodecContext * codec, PayloadContext * xiph_data)
+ AVCodecParameters *par, PayloadContext * xiph_data)
{
unsigned num_packed, num_headers, length, length1, length2, extradata_alloc;
uint8_t *ptr;
if (packed_headers_end - packed_headers < 9) {
- av_log(codec, AV_LOG_ERROR,
+ av_log(s, AV_LOG_ERROR,
"Invalid %td byte packed header.",
packed_headers_end - packed_headers);
return AVERROR_INVALIDDATA;
@@ -245,7 +246,7 @@ parse_packed_headers(const uint8_t * packed_headers,
length2 = get_base128(&packed_headers, packed_headers_end);
if (num_packed != 1 || num_headers > 3) {
- av_log(codec, AV_LOG_ERROR,
+ av_log(s, AV_LOG_ERROR,
"Unimplemented number of headers: %d packed headers, %d headers\n",
num_packed, num_headers);
return AVERROR_PATCHWELCOME;
@@ -253,7 +254,7 @@ parse_packed_headers(const uint8_t * packed_headers,
if (packed_headers_end - packed_headers != length ||
length1 > length || length2 > length - length1) {
- av_log(codec, AV_LOG_ERROR,
+ av_log(s, AV_LOG_ERROR,
"Bad packed header lengths (%d,%d,%td,%d)\n", length1,
length2, packed_headers_end - packed_headers, length);
return AVERROR_INVALIDDATA;
@@ -265,9 +266,9 @@ parse_packed_headers(const uint8_t * packed_headers,
* -- AV_INPUT_BUFFER_PADDING_SIZE required */
extradata_alloc = length + length/255 + 3 + AV_INPUT_BUFFER_PADDING_SIZE;
- ptr = codec->extradata = av_malloc(extradata_alloc);
+ ptr = par->extradata = av_malloc(extradata_alloc);
if (!ptr) {
- av_log(codec, AV_LOG_ERROR, "Out of memory\n");
+ av_log(s, AV_LOG_ERROR, "Out of memory\n");
return AVERROR(ENOMEM);
}
*ptr++ = 2;
@@ -275,9 +276,9 @@ parse_packed_headers(const uint8_t * packed_headers,
ptr += av_xiphlacing(ptr, length2);
memcpy(ptr, packed_headers, length);
ptr += length;
- codec->extradata_size = ptr - codec->extradata;
+ par->extradata_size = ptr - par->extradata;
// clear out remaining parts of the buffer
- memset(ptr, 0, extradata_alloc - codec->extradata_size);
+ memset(ptr, 0, extradata_alloc - par->extradata_size);
return 0;
}
@@ -287,16 +288,16 @@ static int xiph_parse_fmtp_pair(AVFormatContext *s,
PayloadContext *xiph_data,
const char *attr, const char *value)
{
- AVCodecContext *codec = stream->codec;
+ AVCodecParameters *par = stream->codecpar;
int result = 0;
if (!strcmp(attr, "sampling")) {
if (!strcmp(value, "YCbCr-4:2:0")) {
- codec->pix_fmt = AV_PIX_FMT_YUV420P;
+ par->format = AV_PIX_FMT_YUV420P;
} else if (!strcmp(value, "YCbCr-4:4:2")) {
- codec->pix_fmt = AV_PIX_FMT_YUV422P;
+ par->format = AV_PIX_FMT_YUV422P;
} else if (!strcmp(value, "YCbCr-4:4:4")) {
- codec->pix_fmt = AV_PIX_FMT_YUV444P;
+ par->format = AV_PIX_FMT_YUV444P;
} else {
av_log(s, AV_LOG_ERROR,
"Unsupported pixel format %s\n", attr);
@@ -305,12 +306,12 @@ static int xiph_parse_fmtp_pair(AVFormatContext *s,
} else if (!strcmp(attr, "width")) {
/* This is an integer between 1 and 1048561
* and MUST be in multiples of 16. */
- codec->width = atoi(value);
+ par->width = atoi(value);
return 0;
} else if (!strcmp(attr, "height")) {
/* This is an integer between 1 and 1048561
* and MUST be in multiples of 16. */
- codec->height = atoi(value);
+ par->height = atoi(value);
return 0;
} else if (!strcmp(attr, "delivery-method")) {
/* Possible values are: inline, in_band, out_band/specific_name. */
@@ -334,7 +335,7 @@ static int xiph_parse_fmtp_pair(AVFormatContext *s,
av_base64_decode(decoded_packet, value, decoded_alloc);
result = parse_packed_headers
- (decoded_packet, decoded_packet + packet_size, codec,
+ (s, decoded_packet, decoded_packet + packet_size, par,
xiph_data);
} else {
av_log(s, AV_LOG_ERROR,