Commit 4db0e8fd authored by Michael Niedermayer's avatar Michael Niedermayer

Merge commit 'b7624944'

* commit 'b7624944':
  sdp: Simplify parsing/conversion of H264 extradata
Merged-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parents a52384dc b7624944
...@@ -156,8 +156,9 @@ static char *extradata2psets(AVCodecContext *c) ...@@ -156,8 +156,9 @@ static char *extradata2psets(AVCodecContext *c)
const uint8_t *r; const uint8_t *r;
static const char pset_string[] = "; sprop-parameter-sets="; static const char pset_string[] = "; sprop-parameter-sets=";
static const char profile_string[] = "; profile-level-id="; static const char profile_string[] = "; profile-level-id=";
uint8_t *orig_extradata = NULL; uint8_t *extradata = c->extradata;
int orig_extradata_size = 0; int extradata_size = c->extradata_size;
uint8_t *tmpbuf = NULL;
const uint8_t *sps = NULL, *sps_end; const uint8_t *sps = NULL, *sps_end;
if (c->extradata_size > MAX_EXTRADATA_SIZE) { if (c->extradata_size > MAX_EXTRADATA_SIZE) {
...@@ -166,44 +167,28 @@ static char *extradata2psets(AVCodecContext *c) ...@@ -166,44 +167,28 @@ static char *extradata2psets(AVCodecContext *c)
return NULL; return NULL;
} }
if (c->extradata[0] == 1) { if (c->extradata[0] == 1) {
uint8_t *dummy_p; if (ff_avc_write_annexb_extradata(c->extradata, &extradata,
int dummy_int; &extradata_size))
AVBitStreamFilterContext *bsfc= av_bitstream_filter_init("h264_mp4toannexb");
if (!bsfc) {
av_log(c, AV_LOG_ERROR, "Cannot open the h264_mp4toannexb BSF!\n");
return NULL; return NULL;
} tmpbuf = extradata;
orig_extradata_size = c->extradata_size;
orig_extradata = av_mallocz(orig_extradata_size +
FF_INPUT_BUFFER_PADDING_SIZE);
if (!orig_extradata) {
av_bitstream_filter_close(bsfc);
return NULL;
}
memcpy(orig_extradata, c->extradata, orig_extradata_size);
av_bitstream_filter_filter(bsfc, c, NULL, &dummy_p, &dummy_int, NULL, 0, 0);
av_bitstream_filter_close(bsfc);
} }
psets = av_mallocz(MAX_PSET_SIZE); psets = av_mallocz(MAX_PSET_SIZE);
if (!psets) { if (!psets) {
av_log(c, AV_LOG_ERROR, "Cannot allocate memory for the parameter sets.\n"); av_log(c, AV_LOG_ERROR, "Cannot allocate memory for the parameter sets.\n");
av_free(orig_extradata); av_free(tmpbuf);
return NULL; return NULL;
} }
memcpy(psets, pset_string, strlen(pset_string)); memcpy(psets, pset_string, strlen(pset_string));
p = psets + strlen(pset_string); p = psets + strlen(pset_string);
r = ff_avc_find_startcode(c->extradata, c->extradata + c->extradata_size); r = ff_avc_find_startcode(extradata, extradata + extradata_size);
while (r < c->extradata + c->extradata_size) { while (r < extradata + extradata_size) {
const uint8_t *r1; const uint8_t *r1;
uint8_t nal_type; uint8_t nal_type;
while (!*(r++)); while (!*(r++));
nal_type = *r & 0x1f; nal_type = *r & 0x1f;
r1 = ff_avc_find_startcode(r, c->extradata + c->extradata_size); r1 = ff_avc_find_startcode(r, extradata + extradata_size);
if (nal_type != 7 && nal_type != 8) { /* Only output SPS and PPS */ if (nal_type != 7 && nal_type != 8) { /* Only output SPS and PPS */
r = r1; r = r1;
continue; continue;
...@@ -219,6 +204,7 @@ static char *extradata2psets(AVCodecContext *c) ...@@ -219,6 +204,7 @@ static char *extradata2psets(AVCodecContext *c)
if (!av_base64_encode(p, MAX_PSET_SIZE - (p - psets), r, r1 - r)) { if (!av_base64_encode(p, MAX_PSET_SIZE - (p - psets), r, r1 - r)) {
av_log(c, AV_LOG_ERROR, "Cannot Base64-encode %"PTRDIFF_SPECIFIER" %"PTRDIFF_SPECIFIER"!\n", MAX_PSET_SIZE - (p - psets), r1 - r); av_log(c, AV_LOG_ERROR, "Cannot Base64-encode %"PTRDIFF_SPECIFIER" %"PTRDIFF_SPECIFIER"!\n", MAX_PSET_SIZE - (p - psets), r1 - r);
av_free(psets); av_free(psets);
av_free(tmpbuf);
return NULL; return NULL;
} }
...@@ -231,11 +217,7 @@ static char *extradata2psets(AVCodecContext *c) ...@@ -231,11 +217,7 @@ static char *extradata2psets(AVCodecContext *c)
ff_data_to_hex(p, sps + 1, 3, 0); ff_data_to_hex(p, sps + 1, 3, 0);
p[6] = '\0'; p[6] = '\0';
} }
if (orig_extradata) { av_free(tmpbuf);
av_free(c->extradata);
c->extradata = orig_extradata;
c->extradata_size = orig_extradata_size;
}
return psets; return psets;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment