| 53 | } |
| 54 | |
| 55 | static int amr_parse(AVCodecParserContext *s1, |
| 56 | AVCodecContext *avctx, |
| 57 | const uint8_t **poutbuf, int *poutbuf_size, |
| 58 | const uint8_t *buf, int buf_size) |
| 59 | { |
| 60 | AMRParseContext *s = s1->priv_data; |
| 61 | ParseContext *pc = &s->pc; |
| 62 | int next = END_NOT_FOUND; |
| 63 | |
| 64 | *poutbuf_size = 0; |
| 65 | *poutbuf = NULL; |
| 66 | |
| 67 | if (!avctx->ch_layout.nb_channels) { |
| 68 | av_channel_layout_uninit(&avctx->ch_layout); |
| 69 | avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO; |
| 70 | } |
| 71 | |
| 72 | if (s1->flags & PARSER_FLAG_COMPLETE_FRAMES) { |
| 73 | next = buf_size; |
| 74 | } else { |
| 75 | int ch, offset = 0; |
| 76 | |
| 77 | for (ch = s->current_channel; ch < avctx->ch_layout.nb_channels; ch++) { |
| 78 | if (s->remaining >= 0) { |
| 79 | next = s->remaining; |
| 80 | } else { |
| 81 | int mode = (buf[offset] >> 3) & 0x0F; |
| 82 | |
| 83 | if (avctx->codec_id == AV_CODEC_ID_AMR_NB) { |
| 84 | next = amrnb_packed_size[mode]; |
| 85 | } else if (avctx->codec_id == AV_CODEC_ID_AMR_WB) { |
| 86 | next = amrwb_packed_size[mode]; |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | offset += next; |
| 91 | if (offset >= buf_size) { |
| 92 | s->remaining = offset - buf_size; |
| 93 | next = END_NOT_FOUND; |
| 94 | break; |
| 95 | } else { |
| 96 | s->remaining = -1; |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | s->current_channel = ch % avctx->ch_layout.nb_channels; |
| 101 | if (s->remaining < 0) |
| 102 | next = offset; |
| 103 | |
| 104 | if (next != END_NOT_FOUND) { |
| 105 | if (s->cumulated_size < UINT64_MAX - next) { |
| 106 | s->cumulated_size += next; |
| 107 | /* Both AMR formats have 50 frames per second */ |
| 108 | avctx->bit_rate = s->cumulated_size / ++s->block_count * 8 * 50; |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) { |
nothing calls this directly
no test coverage detected