Changes between Version 9 and Version 10 of MEDIA_ENGINE_IMPL_MAIN_R3


Ignore:
Timestamp:
08/31/09 16:20:12 (16 years ago)
Author:
stefan
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • MEDIA_ENGINE_IMPL_MAIN_R3

    v9 v10  
    3232 
    3333= Design = 
    34 ^(Describe your design here.)^ 
     34So, in order to make audio working, we'll make Decoder C++ class which will unite functionality of video decoding that are provided in [wiki:MEDIA_ENGINE_IMPL_MAIN_R2] and audio decoding from this task. 
     35prototype of Decoder.h : 
     36 
     37{{{ 
     38#ifndef DECODER_H_ 
     39#define DECODER_H_ 
     40 
     41class Decoder { 
     42public: 
     43    Decoder(); 
     44    virtual ~Decoder(); 
     45 
     46    Code open(); 
     47    void close(); 
     48    int seek(int time); 
     49    bool readFrame(); 
     50    int* decodeFrame(); 
     51    int getWidth() const; 
     52    int getHeight() const; 
     53    int getLinesize() const; 
     54    int getDuration() const; 
     55 
     56    bool isOpen(); 
     57 
     58    bool readAudioFrame(); 
     59    int* decodeAudioFrame(int*); 
     60    int* saveAudioBuffer(uint8_t*, int); 
     61 
     62private: 
     63    bool is_open; 
     64    bool is_closed; 
     65 
     66    AVFormatContext *pFormatContext; 
     67    AVCodecContext *pCodecCtx; 
     68    int videoStream, audiostream; 
     69    uint8_t *buffer, *audio_buf; 
     70    AVFrame *pFrame, *pFrameRGB; 
     71    AVCodec *pCodec, *aCodec; 
     72    PixelFormat pixFMT; 
     73 
     74    int* saveFrame(AVFrame *pFrame, int width, int height); 
     75 
     76    AVPacket packet; 
     77    int buf_size; 
     78}; 
     79 
     80#endif /* DECODER_H_ */ 
     81}}} 
     82 
     83 
     84 
     85A decode method for the audio stream in this class should be provided: 
     86prototype: 
     87{{{ 
     88int* AudioPlayer::decodeAudioFrame(int* size) { 
     89 
     90    uint8_t* audio_pkt_data = NULL; 
     91    int audio_pkt_size = 0; 
     92 
     93    int len1; 
     94     
     95    audio_pkt_data = packet.data; 
     96 
     97    audio_pkt_size = packet.size; 
     98    audio_buf =(uint8_t*) av_malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE*sizeof(uint8_t)); 
     99    buf_size = AVCODEC_MAX_AUDIO_FRAME_SIZE; 
     100     
     101    packet.data =(uint8_t*) av_malloc((audio_pkt_size + FF_INPUT_BUFFER_PADDING_SIZE)*sizeof(uint8_t)); 
     102    memcpy(packet.data, audio_pkt_data, audio_pkt_size); 
     103    while (audio_pkt_size > 0) { 
     104        int data_size = buf_size; 
     105        //fprintf(stderr,"decodeAudioFrame: Trying to decode packet!\n"); 
     106        //fprintf(stderr,"decodeAudioFrame: data_size before decode: %d.\n",data_size); 
     107        len1 = avcodec_decode_audio3(aCodecCtx, (int16_t *) audio_buf, 
     108                &data_size, &packet); 
     109        //fprintf(stderr,"decodeAudioFrame: Number of bytes decoded: %d.\n",len1); 
     110        //fprintf(stderr,"decodeAudioFrame: data_size after decode: %d.\n",data_size); 
     111        if (len1 < 0) { 
     112            //fprintf(stderr,"decodeAudioFrame: ERROR decoding!\n"); 
     113            /* if error, skip frame */ 
     114            audio_pkt_size = 0; 
     115            break; 
     116        } 
     117        //fprintf(stderr,"decodeAudioFrame: Sound probably decoded...\n"); 
     118        audio_pkt_data += len1; 
     119        audio_pkt_size -= len1; 
     120        if (data_size <= 0) { 
     121            //fprintf(stderr,"decodeAudioFrame: SHOULDN'T GET HERE!\n"); 
     122            continue; 
     123        }/* We have data, return it and come back for more later */ 
     124        size = &data_size; 
     125        //fprintf(stderr,"decodeAudioFrame: Gets before saving buffer with size: %d\n", *size); 
     126        return saveAudioBuffer(audio_buf, data_size); 
     127    } 
     128}}} 
    35129 
    36130= Implementation =