History

avcodec/hevc_sei: switch to AVBufferRef buffer for a53 caption

Limin Wang committed 6 years ago

Commit dbb05171 parent 99f505d3 files · +16 −17Browse files

Unified · Split

3 files
  1. libavcodec/hevc_sei.c +7 −7
  2. libavcodec/hevc_sei.h +1 −2
  3. libavcodec/hevcdec.c +8 −8
libavcodec/hevc_sei.c+7−7
@@ -177,7 +177,8 @@ static int decode_registered_user_data_closed_caption(HEVCSEIA53Caption *s, GetB · 176 unmodified lines
177177 size -= 2;
178178
179179 if (cc_count && size >= cc_count * 3) {
180− const uint64_t new_size = (s->a53_caption_size + cc_count
180+ int old_size = s->buf_ref ? s->buf_ref->size : 0;
181+ const uint64_t new_size = (old_size + cc_count
181182 * UINT64_C(3));
182183 int i, ret;
183184
@@ -185,14 +186,14 @@ static int decode_registered_user_data_closed_caption(HEVCSEIA53Caption *s, GetB · 1 unmodified line
185186 return AVERROR(EINVAL);
186187
187188 /* Allow merging of the cc data from two fields. */
188− ret = av_reallocp(&s->a53_caption, new_size);
189+ ret = av_buffer_realloc(&s->buf_ref, new_size);
189190 if (ret < 0)
190191 return ret;
191192
192193 for (i = 0; i < cc_count; i++) {
193− s->a53_caption[s->a53_caption_size++] = get_bits(gb, 8);
194− s->a53_caption[s->a53_caption_size++] = get_bits(gb, 8);
195− s->a53_caption[s->a53_caption_size++] = get_bits(gb, 8);
194+ s->buf_ref->data[old_size++] = get_bits(gb, 8);
195+ s->buf_ref->data[old_size++] = get_bits(gb, 8);
196+ s->buf_ref->data[old_size++] = get_bits(gb, 8);
196197 }
197198 skip_bits(gb, 8); // marker_bits
198199 }
@@ -363,6 +364,5 @@ int ff_hevc_decode_nal_sei(GetBitContext *gb, void *logctx, HEVCSEI *s, · 164 unmodified lines
363364
364365 void ff_hevc_reset_sei(HEVCSEI *s)
365366 {
366− s->a53_caption.a53_caption_size = 0;
367− av_freep(&s->a53_caption.a53_caption);
367+ av_buffer_unref(&s->a53_caption.buf_ref);
368368 }
libavcodec/hevc_sei.h+1−2
@@ -83,8 +83,7 @@ typedef struct HEVCSEIPictureTiming { · 82 unmodified lines
8383 } HEVCSEIPictureTiming;
8484
8585 typedef struct HEVCSEIA53Caption {
86− int a53_caption_size;
87− uint8_t *a53_caption;
86+ AVBufferRef *buf_ref;
8887 } HEVCSEIA53Caption;
8988
9089 typedef struct HEVCSEIMasteringDisplay {
libavcodec/hevcdec.c+8−8
@@ -2778,14 +2778,14 @@ static int set_side_data(HEVCContext *s) · 2777 unmodified lines
27782778 metadata->MaxCLL, metadata->MaxFALL);
27792779 }
27802780
2781− if (s->sei.a53_caption.a53_caption) {
2782− AVFrameSideData* sd = av_frame_new_side_data(out,
2783− AV_FRAME_DATA_A53_CC,
2784− s->sei.a53_caption.a53_caption_size);
2785− if (sd)
2786− memcpy(sd->data, s->sei.a53_caption.a53_caption, s->sei.a53_caption.a53_caption_size);
2787− av_freep(&s->sei.a53_caption.a53_caption);
2788− s->sei.a53_caption.a53_caption_size = 0;
2781+ if (s->sei.a53_caption.buf_ref) {
2782+ HEVCSEIA53Caption *a53 = &s->sei.a53_caption;
2783+
2784+ AVFrameSideData *sd = av_frame_new_side_data_from_buf(out, AV_FRAME_DATA_A53_CC, a53->buf_ref);
2785+ if (!sd)
2786+ av_buffer_unref(&a53->buf_ref);
2787+ a53->buf_ref = NULL;
2788+
27892789 s->avctx->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS;
27902790 }
27912791

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t