MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / mpeg_decode_a53_cc

Function mpeg_decode_a53_cc

libavcodec/mpeg12dec.c:1903–2106  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1901}
1902
1903static int mpeg_decode_a53_cc(AVCodecContext *avctx,
1904 const uint8_t *p, int buf_size)
1905{
1906 Mpeg1Context *s1 = avctx->priv_data;
1907
1908 if ((!s1->cc_format || s1->cc_format == CC_FORMAT_A53_PART4) &&
1909 buf_size >= 6 &&
1910 p[0] == 'G' && p[1] == 'A' && p[2] == '9' && p[3] == '4' &&
1911 p[4] == 3 && (p[5] & 0x40)) {
1912 /* extract A53 Part 4 CC data */
1913 int cc_count = p[5] & 0x1f;
1914 if (cc_count > 0 && buf_size >= 7 + cc_count * 3) {
1915 int old_size = s1->a53_buf_ref ? s1->a53_buf_ref->size : 0;
1916 const uint64_t new_size = (old_size + cc_count
1917 * UINT64_C(3));
1918 int ret;
1919
1920 if (new_size > 3*A53_MAX_CC_COUNT)
1921 return AVERROR(EINVAL);
1922
1923 ret = av_buffer_realloc(&s1->a53_buf_ref, new_size);
1924 if (ret >= 0)
1925 memcpy(s1->a53_buf_ref->data + old_size, p + 7, cc_count * UINT64_C(3));
1926
1927 mpeg_set_cc_format(avctx, CC_FORMAT_A53_PART4, "A/53 Part 4");
1928 }
1929 return 1;
1930 } else if ((!s1->cc_format || s1->cc_format == CC_FORMAT_SCTE20) &&
1931 buf_size >= 2 &&
1932 p[0] == 0x03 && (p[1]&0x7f) == 0x01) {
1933 /* extract SCTE-20 CC data */
1934 GetBitContext gb;
1935 int cc_count = 0;
1936 int i, ret;
1937
1938 ret = init_get_bits8(&gb, p + 2, buf_size - 2);
1939 if (ret < 0)
1940 return ret;
1941 cc_count = get_bits(&gb, 5);
1942 if (cc_count > 0) {
1943 int old_size = s1->a53_buf_ref ? s1->a53_buf_ref->size : 0;
1944 const uint64_t new_size = (old_size + cc_count
1945 * UINT64_C(3));
1946 if (new_size > 3*A53_MAX_CC_COUNT)
1947 return AVERROR(EINVAL);
1948
1949 ret = av_buffer_realloc(&s1->a53_buf_ref, new_size);
1950 if (ret >= 0) {
1951 uint8_t field, cc1, cc2;
1952 uint8_t *cap = s1->a53_buf_ref->data + old_size;
1953
1954 memset(cap, 0, cc_count * 3);
1955 for (i = 0; i < cc_count && get_bits_left(&gb) >= 26; i++) {
1956 skip_bits(&gb, 2); // priority
1957 field = get_bits(&gb, 2);
1958 skip_bits(&gb, 5); // line_offset
1959 cc1 = get_bits(&gb, 8);
1960 cc2 = get_bits(&gb, 8);

Callers 1

mpeg_decode_user_dataFunction · 0.85

Calls 6

av_buffer_reallocFunction · 0.85
mpeg_set_cc_formatFunction · 0.85
init_get_bits8Function · 0.85
get_bits_leftFunction · 0.85
skip_bitsFunction · 0.85
get_bitsFunction · 0.70

Tested by

no test coverage detected