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

Function tak_parse

libavcodec/tak_parser.c:39–125  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37} TAKParseContext;
38
39static int tak_parse(AVCodecParserContext *s, AVCodecContext *avctx,
40 const uint8_t **poutbuf, int *poutbuf_size,
41 const uint8_t *buf, int buf_size)
42{
43 TAKParseContext *t = s->priv_data;
44 ParseContext *pc = &t->pc;
45 int next = END_NOT_FOUND;
46 GetBitContext gb;
47 int consumed = 0;
48 int needed = buf_size ? TAK_MAX_FRAME_HEADER_BYTES : 8;
49 int ret;
50
51 *poutbuf = buf;
52 *poutbuf_size = buf_size;
53
54 if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) {
55 TAKStreamInfo ti;
56 if ((ret = init_get_bits8(&gb, buf, buf_size)) < 0)
57 return buf_size;
58 if (!ff_tak_decode_frame_header(avctx, &gb, &ti, 127))
59 s->duration = t->ti.last_frame_samples ? t->ti.last_frame_samples
60 : t->ti.frame_samples;
61 return buf_size;
62 }
63
64 while (buf_size || t->index + needed <= pc->index) {
65 if (buf_size && t->index + TAK_MAX_FRAME_HEADER_BYTES > pc->index) {
66 int tmp_buf_size = FFMIN(TAK_MAX_FRAME_HEADER_BYTES,
67 buf_size);
68 const uint8_t *tmp_buf = buf;
69
70 if (ff_combine_frame(pc, END_NOT_FOUND, &tmp_buf, &tmp_buf_size) != -1)
71 goto fail;
72 consumed += tmp_buf_size;
73 buf += tmp_buf_size;
74 buf_size -= tmp_buf_size;
75 }
76
77 for (; t->index + needed <= pc->index; t->index++) {
78 if (pc->buffer[ t->index ] == 0xFF &&
79 pc->buffer[ t->index + 1 ] == 0xA0) {
80 TAKStreamInfo ti;
81
82 if ((ret = init_get_bits8(&gb, pc->buffer + t->index,
83 pc->index - t->index)) < 0)
84 goto fail;
85 if (!ff_tak_decode_frame_header(avctx, &gb,
86 pc->frame_start_found ? &ti : &t->ti, 127) &&
87 !ff_tak_check_crc(pc->buffer + t->index,
88 get_bits_count(&gb) / 8)) {
89 if (!pc->frame_start_found) {
90 pc->frame_start_found = 1;
91 s->duration = t->ti.last_frame_samples ?
92 t->ti.last_frame_samples :
93 t->ti.frame_samples;
94 s->key_frame = !!(t->ti.flags & TAK_FRAME_FLAG_HAS_INFO);
95 } else {
96 pc->frame_start_found = 0;

Callers

nothing calls this directly

Calls 5

init_get_bits8Function · 0.85
ff_combine_frameFunction · 0.85
ff_tak_check_crcFunction · 0.85
get_bits_countFunction · 0.85

Tested by

no test coverage detected