| 32 | } SBCParseContext; |
| 33 | |
| 34 | static int sbc_parse_header(AVCodecParserContext *s, AVCodecContext *avctx, |
| 35 | const uint8_t *data, size_t len) |
| 36 | { |
| 37 | static const int sample_rates[4] = { 16000, 32000, 44100, 48000 }; |
| 38 | int sr, blocks, mode, subbands, bitpool, channels, joint; |
| 39 | int length; |
| 40 | |
| 41 | if (len < 3) |
| 42 | return -1; |
| 43 | |
| 44 | if (data[0] == MSBC_SYNCWORD && data[1] == 0 && data[2] == 0) { |
| 45 | av_channel_layout_uninit(&avctx->ch_layout); |
| 46 | avctx->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; |
| 47 | avctx->ch_layout.nb_channels = 1; |
| 48 | avctx->sample_rate = 16000; |
| 49 | avctx->frame_size = 120; |
| 50 | s->duration = avctx->frame_size; |
| 51 | return 57; |
| 52 | } |
| 53 | |
| 54 | if (data[0] != SBC_SYNCWORD) |
| 55 | return -2; |
| 56 | |
| 57 | sr = (data[1] >> 6) & 0x03; |
| 58 | blocks = (((data[1] >> 4) & 0x03) + 1) << 2; |
| 59 | mode = (data[1] >> 2) & 0x03; |
| 60 | subbands = (((data[1] >> 0) & 0x01) + 1) << 2; |
| 61 | bitpool = data[2]; |
| 62 | |
| 63 | channels = mode == SBC_MODE_MONO ? 1 : 2; |
| 64 | joint = mode == SBC_MODE_JOINT_STEREO; |
| 65 | |
| 66 | length = 4 + (subbands * channels) / 2 |
| 67 | + ((((mode == SBC_MODE_DUAL_CHANNEL) + 1) * blocks * bitpool |
| 68 | + (joint * subbands)) + 7) / 8; |
| 69 | |
| 70 | av_channel_layout_uninit(&avctx->ch_layout); |
| 71 | avctx->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; |
| 72 | avctx->ch_layout.nb_channels = channels; |
| 73 | avctx->sample_rate = sample_rates[sr]; |
| 74 | avctx->frame_size = subbands * blocks; |
| 75 | s->duration = avctx->frame_size; |
| 76 | return length; |
| 77 | } |
| 78 | |
| 79 | static int sbc_parse(AVCodecParserContext *s, AVCodecContext *avctx, |
| 80 | const uint8_t **poutbuf, int *poutbuf_size, |
no test coverage detected