LCOV - code coverage report
Current view: top level - src/libavcodec - aac_ac3_parser.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 45 49 91.8 %
Date: 2017-04-28 19:02:26 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /*
       2             :  * Common AAC and AC-3 parser
       3             :  * Copyright (c) 2003 Fabrice Bellard
       4             :  * Copyright (c) 2003 Michael Niedermayer
       5             :  *
       6             :  * This file is part of FFmpeg.
       7             :  *
       8             :  * FFmpeg is free software; you can redistribute it and/or
       9             :  * modify it under the terms of the GNU Lesser General Public
      10             :  * License as published by the Free Software Foundation; either
      11             :  * version 2.1 of the License, or (at your option) any later version.
      12             :  *
      13             :  * FFmpeg is distributed in the hope that it will be useful,
      14             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      15             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      16             :  * Lesser General Public License for more details.
      17             :  *
      18             :  * You should have received a copy of the GNU Lesser General Public
      19             :  * License along with FFmpeg; if not, write to the Free Software
      20             :  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
      21             :  */
      22             : 
      23             : #include "libavutil/channel_layout.h"
      24             : #include "libavutil/common.h"
      25             : #include "parser.h"
      26             : #include "aac_ac3_parser.h"
      27             : 
      28       10472 : int ff_aac_ac3_parse(AVCodecParserContext *s1,
      29             :                      AVCodecContext *avctx,
      30             :                      const uint8_t **poutbuf, int *poutbuf_size,
      31             :                      const uint8_t *buf, int buf_size)
      32             : {
      33       10472 :     AACAC3ParseContext *s = s1->priv_data;
      34       10472 :     ParseContext *pc = &s->pc;
      35             :     int len, i;
      36             :     int new_frame_start;
      37       10472 :     int got_frame = 0;
      38             : 
      39             : get_next:
      40       16335 :     i=END_NOT_FOUND;
      41       16335 :     if(s->remaining_size <= buf_size){
      42       13232 :         if(s->remaining_size && !s->need_next_header){
      43        5846 :             i= s->remaining_size;
      44        5846 :             s->remaining_size = 0;
      45             :         }else{ //we need a header first
      46        7386 :             len=0;
      47       48744 :             for(i=s->remaining_size; i<buf_size; i++){
      48       48251 :                 s->state = (s->state<<8) + buf[i];
      49       48251 :                 if((len=s->sync(s->state, s, &s->need_next_header, &new_frame_start)))
      50        6893 :                     break;
      51             :             }
      52        7386 :             if(len<=0){
      53         493 :                 i=END_NOT_FOUND;
      54             :             }else{
      55        6893 :                 got_frame = 1;
      56        6893 :                 s->state=0;
      57        6893 :                 i-= s->header_size -1;
      58        6893 :                 s->remaining_size = len;
      59        6893 :                 if(!new_frame_start || pc->index+i<=0){
      60        5863 :                     s->remaining_size += i;
      61        5863 :                     goto get_next;
      62             :                 }
      63             :             }
      64             :         }
      65             :     }
      66             : 
      67       10472 :     if(ff_combine_frame(pc, i, &buf, &buf_size)<0){
      68        3528 :         s->remaining_size -= FFMIN(s->remaining_size, buf_size);
      69        3528 :         *poutbuf = NULL;
      70        3528 :         *poutbuf_size = 0;
      71        3528 :         return buf_size;
      72             :     }
      73             : 
      74        6944 :     *poutbuf = buf;
      75        6944 :     *poutbuf_size = buf_size;
      76             : 
      77             :     /* update codec info */
      78        6944 :     if(s->codec_id)
      79        2234 :         avctx->codec_id = s->codec_id;
      80             : 
      81        6944 :     if (got_frame) {
      82             :         /* Due to backwards compatible HE-AAC the sample rate, channel count,
      83             :            and total number of samples found in an AAC ADTS header are not
      84             :            reliable. Bit rate is still accurate because the total frame
      85             :            duration in seconds is still correct (as is the number of bits in
      86             :            the frame). */
      87        4259 :         if (avctx->codec_id != AV_CODEC_ID_AAC) {
      88        1394 :             avctx->sample_rate = s->sample_rate;
      89             : 
      90             :             /* (E-)AC-3: allow downmixing to stereo or mono */
      91        2779 :             if (s->channels > 1 &&
      92        1385 :                 avctx->request_channel_layout == AV_CH_LAYOUT_MONO) {
      93           0 :                 avctx->channels       = 1;
      94           0 :                 avctx->channel_layout = AV_CH_LAYOUT_MONO;
      95        1586 :             } else if (s->channels > 2 &&
      96         192 :                        avctx->request_channel_layout == AV_CH_LAYOUT_STEREO) {
      97           0 :                 avctx->channels       = 2;
      98           0 :                 avctx->channel_layout = AV_CH_LAYOUT_STEREO;
      99             :             } else {
     100        1394 :                 avctx->channels = s->channels;
     101        1394 :                 avctx->channel_layout = s->channel_layout;
     102             :             }
     103        1394 :             s1->duration = s->samples;
     104        1394 :             avctx->audio_service_type = s->service_type;
     105             :         }
     106             : 
     107        4259 :         avctx->bit_rate = s->bit_rate;
     108             :     }
     109             : 
     110        6944 :     return i;
     111             : }

Generated by: LCOV version 1.13