161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti/*-------------------------------------------------------------------------- 361e21a4fe27118141afc13323807f83b733cf426Uday Kishore PasupuletiCopyright (c) 2010-2014, The Linux Foundation. All rights reserved. 461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 561e21a4fe27118141afc13323807f83b733cf426Uday Kishore PasupuletiRedistribution and use in source and binary forms, with or without 661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletimodification, are permitted provided that the following conditions are met: 761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti * Redistributions of source code must retain the above copyright 861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti notice, this list of conditions and the following disclaimer. 961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti * Redistributions in binary form must reproduce the above copyright 1061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti notice, this list of conditions and the following disclaimer in the 1161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti documentation and/or other materials provided with the distribution. 1261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti * Neither the name of The Linux Foundation nor 1361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti the names of its contributors may be used to endorse or promote 1461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti products derived from this software without specific prior written 1561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti permission. 1661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 1761e21a4fe27118141afc13323807f83b733cf426Uday Kishore PasupuletiTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 1861e21a4fe27118141afc13323807f83b733cf426Uday Kishore PasupuletiAND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1961e21a4fe27118141afc13323807f83b733cf426Uday Kishore PasupuletiIMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 2061e21a4fe27118141afc13323807f83b733cf426Uday Kishore PasupuletiNON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 2161e21a4fe27118141afc13323807f83b733cf426Uday Kishore PasupuletiCONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 2261e21a4fe27118141afc13323807f83b733cf426Uday Kishore PasupuletiEXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 2361e21a4fe27118141afc13323807f83b733cf426Uday Kishore PasupuletiPROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 2461e21a4fe27118141afc13323807f83b733cf426Uday Kishore PasupuletiOR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 2561e21a4fe27118141afc13323807f83b733cf426Uday Kishore PasupuletiWHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 2661e21a4fe27118141afc13323807f83b733cf426Uday Kishore PasupuletiOTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 2761e21a4fe27118141afc13323807f83b733cf426Uday Kishore PasupuletiADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti--------------------------------------------------------------------------*/ 2961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 3061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 3161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti/* 3261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti An Open max test application .... 3361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti*/ 3461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 3561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti#include <stdio.h> 3661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti#include <string.h> 3761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti#include <stdlib.h> 3861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti#include <unistd.h> 3961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti#include <fcntl.h> 4061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti#include <sys/types.h> 4161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti#include <sys/mman.h> 4261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti#include <time.h> 4361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti#include <sys/ioctl.h> 4461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti#include "OMX_Core.h" 4561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti#include "OMX_Component.h" 4661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti#include "pthread.h" 4761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti#include <signal.h> 4861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 4961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti#include <stdio.h> 5061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti#include <stdlib.h> 5161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti#include <fcntl.h> 5261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti#include <stdint.h> 5361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti#include <sys/mman.h> 5461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti#include <sys/ioctl.h> 5561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti#include<unistd.h> 5661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti#include<string.h> 5761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti#include <pthread.h> 5861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti#include "QOMX_AudioExtensions.h" 5961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti#include "QOMX_AudioIndexExtensions.h" 6061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti#ifdef AUDIOV2 6161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti#include "control.h" 6261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti#endif 6361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 6461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 6561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti#include <linux/ioctl.h> 6661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 6761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletitypedef unsigned char uint8; 6861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletitypedef unsigned char byte; 6961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletitypedef unsigned int uint32; 7061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletitypedef unsigned int uint16; 7161e21a4fe27118141afc13323807f83b733cf426Uday Kishore PasupuletiQOMX_AUDIO_STREAM_INFO_DATA streaminfoparam; 7261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti/* maximum ADTS frame header length */ 7361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletivoid Release_Encoder(); 7461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 7561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti#ifdef AUDIOV2 7661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletiunsigned short session_id; 7761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletiint device_id; 7861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletiint control = 0; 7961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleticonst char *device="handset_tx"; 8061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti#define DIR_TX 2 8161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti#endif 8261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 8361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletiuint32_t samplerate = 8000; 8461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletiuint32_t channels = 1; 8561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletiuint32_t bandmode = 7; 8661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletiuint32_t dtxenable = 0; 8761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletiuint32_t rectime = 0; 8861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletiuint32_t recpath = 0; 8961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletiuint32_t pcmplayback = 0; 9061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletiuint32_t tunnel = 0; 9161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletiuint32_t format = 1; 9261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti#define DEBUG_PRINT printf 9361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletiunsigned to_idle_transition = 0; 9461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletiunsigned long total_pcm_bytes; 9561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 9661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti/************************************************************************/ 9761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti/* GLOBAL INIT */ 9861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti/************************************************************************/ 9961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 10061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti/************************************************************************/ 10161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti/* #DEFINES */ 10261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti/************************************************************************/ 10361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti#define false 0 10461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti#define true 1 10561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 10661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti#define CONFIG_VERSION_SIZE(param) \ 10761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti param.nVersion.nVersion = CURRENT_OMX_SPEC_VERSION;\ 10861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti param.nSize = sizeof(param); 10961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 11061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti#define MIN_BITRATE 4 /* Bit rate 1 - 13.6 , 2 - 6.2 , 3 - 2.7 , 4 - 1.0 kbps*/ 11161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti#define MAX_BITRATE 4 11261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti#define AMR_HEADER_SIZE 6 11361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti#define FAILED(result) (result != OMX_ErrorNone) 11461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 11561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti#define SUCCEEDED(result) (result == OMX_ErrorNone) 11661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 11761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti/************************************************************************/ 11861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti/* GLOBAL DECLARATIONS */ 11961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti/************************************************************************/ 12061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 12161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletipthread_mutex_t lock; 12261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletipthread_cond_t cond; 12361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletipthread_mutex_t elock; 12461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletipthread_cond_t econd; 12561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletipthread_cond_t fcond; 12661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletipthread_mutex_t etb_lock; 12761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletipthread_mutex_t etb_lock1; 12861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletipthread_cond_t etb_cond; 12961e21a4fe27118141afc13323807f83b733cf426Uday Kishore PasupuletiFILE * inputBufferFile; 13061e21a4fe27118141afc13323807f83b733cf426Uday Kishore PasupuletiFILE * outputBufferFile; 13161e21a4fe27118141afc13323807f83b733cf426Uday Kishore PasupuletiOMX_PARAM_PORTDEFINITIONTYPE inputportFmt; 13261e21a4fe27118141afc13323807f83b733cf426Uday Kishore PasupuletiOMX_PARAM_PORTDEFINITIONTYPE outputportFmt; 13361e21a4fe27118141afc13323807f83b733cf426Uday Kishore PasupuletiOMX_AUDIO_PARAM_AMRTYPE amrparam; 13461e21a4fe27118141afc13323807f83b733cf426Uday Kishore PasupuletiOMX_AUDIO_PARAM_PCMMODETYPE pcmparam; 13561e21a4fe27118141afc13323807f83b733cf426Uday Kishore PasupuletiOMX_PORT_PARAM_TYPE portParam; 13661e21a4fe27118141afc13323807f83b733cf426Uday Kishore PasupuletiOMX_PORT_PARAM_TYPE portFmt; 13761e21a4fe27118141afc13323807f83b733cf426Uday Kishore PasupuletiOMX_ERRORTYPE error; 13861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 13961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 14061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 14161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 14261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti#define ID_RIFF 0x46464952 14361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti#define ID_WAVE 0x45564157 14461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti#define ID_FMT 0x20746d66 14561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti#define ID_DATA 0x61746164 14661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 14761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti#define FORMAT_PCM 1 14861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 14961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletistruct wav_header { 15061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti uint32_t riff_id; 15161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti uint32_t riff_sz; 15261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti uint32_t riff_fmt; 15361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti uint32_t fmt_id; 15461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti uint32_t fmt_sz; 15561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti uint16_t audio_format; 15661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti uint16_t num_channels; 15761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti uint32_t sample_rate; 15861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti uint32_t byte_rate; /* sample_rate * num_channels * bps / 8 */ 15961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti uint16_t block_align; /* num_channels * bps / 8 */ 16061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti uint16_t bits_per_sample; 16161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti uint32_t data_id; 16261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti uint32_t data_sz; 16361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti}; 16461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletistruct enc_meta_out{ 16561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti unsigned int offset_to_frame; 16661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti unsigned int frame_size; 16761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti unsigned int encoded_pcm_samples; 16861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti unsigned int msw_ts; 16961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti unsigned int lsw_ts; 17061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti unsigned int nflags; 17161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti} __attribute__ ((packed)); 17261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 17361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletistruct qcp_header { 17461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti /* RIFF Section */ 17561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti char riff[4]; 17661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti unsigned int s_riff; 17761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti char qlcm[4]; 17861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 17961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti /* Format chunk */ 18061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti char fmt[4]; 18161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti unsigned int s_fmt; 18261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti char mjr; 18361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti char mnr; 18461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti unsigned int data1; /* UNIQUE ID of the codec */ 18561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti unsigned short data2; 18661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti unsigned short data3; 18761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti char data4[8]; 18861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti unsigned short ver; /* Codec Info */ 18961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti char name[80]; 19061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti unsigned short abps; /* average bits per sec of the codec */ 19161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti unsigned short bytes_per_pkt; 19261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti unsigned short samp_per_block; 19361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti unsigned short samp_per_sec; 19461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti unsigned short bits_per_samp; 19561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti unsigned char vr_num_of_rates; /* Rate Header fmt info */ 19661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti unsigned char rvd1[3]; 19761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti unsigned short vr_bytes_per_pkt[8]; 19861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti unsigned int rvd2[5]; 19961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 20061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti /* Vrat chunk */ 20161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti unsigned char vrat[4]; 20261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti unsigned int s_vrat; 20361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti unsigned int v_rate; 20461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti unsigned int size_in_pkts; 20561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 20661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti /* Data chunk */ 20761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti unsigned char data[4]; 20861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti unsigned int s_data; 20961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti} __attribute__ ((packed)); 21061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 21161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletistatic int totaldatalen = 0; 21261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletistatic int framecnt = 0; 21361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti/************************************************************************/ 21461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti/* GLOBAL INIT */ 21561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti/************************************************************************/ 21661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 21761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletiunsigned int input_buf_cnt = 0; 21861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletiunsigned int output_buf_cnt = 0; 21961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletiint used_ip_buf_cnt = 0; 22061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletivolatile int event_is_done = 0; 22161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletivolatile int ebd_event_is_done = 0; 22261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletivolatile int fbd_event_is_done = 0; 22361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletivolatile int etb_event_is_done = 0; 22461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletiint ebd_cnt; 22561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletiint bInputEosReached = 0; 22661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletiint bOutputEosReached = 0; 22761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletiint bInputEosReached_tunnel = 0; 22861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletistatic int etb_done = 0; 22961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletiint bFlushing = false; 23061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletiint bPause = false; 23161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleticonst char *in_filename; 23261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleticonst char *out_filename; 23361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 23461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletiint timeStampLfile = 0; 23561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletiint timestampInterval = 100; 23661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 23761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti//* OMX Spec Version supported by the wrappers. Version = 1.1 */ 23861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleticonst OMX_U32 CURRENT_OMX_SPEC_VERSION = 0x00000101; 23961e21a4fe27118141afc13323807f83b733cf426Uday Kishore PasupuletiOMX_COMPONENTTYPE* amr_enc_handle = 0; 24061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 24161e21a4fe27118141afc13323807f83b733cf426Uday Kishore PasupuletiOMX_BUFFERHEADERTYPE **pInputBufHdrs = NULL; 24261e21a4fe27118141afc13323807f83b733cf426Uday Kishore PasupuletiOMX_BUFFERHEADERTYPE **pOutputBufHdrs = NULL; 24361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 24461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti/************************************************************************/ 24561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti/* GLOBAL FUNC DECL */ 24661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti/************************************************************************/ 24761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletiint Init_Encoder(char*); 24861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletiint Play_Encoder(); 24961e21a4fe27118141afc13323807f83b733cf426Uday Kishore PasupuletiOMX_STRING aud_comp; 25061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti/**************************************************************************/ 25161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti/* STATIC DECLARATIONS */ 25261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti/**************************************************************************/ 25361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 25461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletistatic int open_audio_file (); 25561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletistatic int Read_Buffer(OMX_BUFFERHEADERTYPE *pBufHdr ); 25661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletistatic OMX_ERRORTYPE Allocate_Buffer ( OMX_COMPONENTTYPE *amr_enc_handle, 25761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti OMX_BUFFERHEADERTYPE ***pBufHdrs, 25861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti OMX_U32 nPortIndex, 25961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti unsigned int bufCntMin, unsigned int bufSize); 26061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 26161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 26261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletistatic OMX_ERRORTYPE EventHandler(OMX_IN OMX_HANDLETYPE hComponent, 26361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti OMX_IN OMX_PTR pAppData, 26461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti OMX_IN OMX_EVENTTYPE eEvent, 26561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti OMX_IN OMX_U32 nData1, OMX_IN OMX_U32 nData2, 26661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti OMX_IN OMX_PTR pEventData); 26761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletistatic OMX_ERRORTYPE EmptyBufferDone(OMX_IN OMX_HANDLETYPE hComponent, 26861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti OMX_IN OMX_PTR pAppData, 26961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti OMX_IN OMX_BUFFERHEADERTYPE* pBuffer); 27061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 27161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletistatic OMX_ERRORTYPE FillBufferDone(OMX_IN OMX_HANDLETYPE hComponent, 27261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti OMX_IN OMX_PTR pAppData, 27361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti OMX_IN OMX_BUFFERHEADERTYPE* pBuffer); 27461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletistatic OMX_ERRORTYPE parse_pcm_header(); 27561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletivoid wait_for_event(void) 27661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti{ 27761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti pthread_mutex_lock(&lock); 27861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("%s: event_is_done=%d", __FUNCTION__, event_is_done); 27961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti while (event_is_done == 0) { 28061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti pthread_cond_wait(&cond, &lock); 28161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 28261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti event_is_done = 0; 28361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti pthread_mutex_unlock(&lock); 28461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti} 28561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 28661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletivoid event_complete(void ) 28761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti{ 28861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti pthread_mutex_lock(&lock); 28961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if (event_is_done == 0) { 29061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti event_is_done = 1; 29161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti pthread_cond_broadcast(&cond); 29261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 29361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti pthread_mutex_unlock(&lock); 29461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti} 29561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 29661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletivoid etb_wait_for_event(void) 29761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti{ 29861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti pthread_mutex_lock(&etb_lock1); 29961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("%s: etb_event_is_done=%d", __FUNCTION__, etb_event_is_done); 30061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti while (etb_event_is_done == 0) { 30161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti pthread_cond_wait(&etb_cond, &etb_lock1); 30261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 30361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti etb_event_is_done = 0; 30461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti pthread_mutex_unlock(&etb_lock1); 30561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti} 30661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 30761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletivoid etb_event_complete(void ) 30861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti{ 30961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti pthread_mutex_lock(&etb_lock1); 31061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if (etb_event_is_done == 0) { 31161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti etb_event_is_done = 1; 31261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti pthread_cond_broadcast(&etb_cond); 31361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 31461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti pthread_mutex_unlock(&etb_lock1); 31561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti} 31661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 31761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 31861e21a4fe27118141afc13323807f83b733cf426Uday Kishore PasupuletiOMX_ERRORTYPE EventHandler(OMX_IN OMX_HANDLETYPE hComponent, 31961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti OMX_IN OMX_PTR pAppData, 32061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti OMX_IN OMX_EVENTTYPE eEvent, 32161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti OMX_IN OMX_U32 nData1, OMX_IN OMX_U32 nData2, 32261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti OMX_IN OMX_PTR pEventData) 32361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti{ 32461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("Function %s \n", __FUNCTION__); 32561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 32661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti /* To remove warning for unused variable to keep prototype same */ 32761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti (void)hComponent; 32861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti (void)pAppData; 32961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti (void)pEventData; 33061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti switch(eEvent) { 33161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti case OMX_EventCmdComplete: 33261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("\n OMX_EventCmdComplete event=%d data1=%u data2=%u\n",(OMX_EVENTTYPE)eEvent, 33361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti nData1,nData2); 33461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti event_complete(); 33561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti break; 33661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti case OMX_EventError: 33761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("\n OMX_EventError \n"); 33861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti break; 33961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti case OMX_EventBufferFlag: 34061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("\n OMX_EventBufferFlag \n"); 34161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti bOutputEosReached = true; 34261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti event_complete(); 34361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti break; 34461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti case OMX_EventPortSettingsChanged: 34561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("\n OMX_EventPortSettingsChanged \n"); 34661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti break; 34761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti default: 34861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("\n Unknown Event \n"); 34961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti break; 35061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 35161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti return OMX_ErrorNone; 35261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti} 35361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 35461e21a4fe27118141afc13323807f83b733cf426Uday Kishore PasupuletiOMX_ERRORTYPE FillBufferDone(OMX_IN OMX_HANDLETYPE hComponent, 35561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti OMX_IN OMX_PTR pAppData, 35661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti OMX_IN OMX_BUFFERHEADERTYPE* pBuffer) 35761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti{ 35861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti size_t bytes_writen = 0; 35961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti size_t total_bytes_writen = 0; 36061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti size_t len = 0; 36161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti struct enc_meta_out *meta = NULL; 36261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti OMX_U8 *src = pBuffer->pBuffer; 36361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti unsigned int num_of_frames = 1; 36461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 36561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti /* To remove warning for unused variable to keep prototype same */ 36661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti (void)pAppData; 36761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 36861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if(((pBuffer->nFlags & OMX_BUFFERFLAG_EOS) == OMX_BUFFERFLAG_EOS)) { 36961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("FBD::EOS on output port\n "); 37061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti bOutputEosReached = true; 37161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti return OMX_ErrorNone; 37261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 37361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if(bInputEosReached_tunnel || bOutputEosReached) 37461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti { 37561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("EOS REACHED NO MORE PROCESSING OF BUFFERS\n"); 37661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti return OMX_ErrorNone; 37761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 37861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if(num_of_frames != src[0]){ 37961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 38061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti printf("Data corrupt\n"); 38161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti return OMX_ErrorNone; 38261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 38361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti /* Skip the first bytes */ 38461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 38561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 38661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 38761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti src += sizeof(unsigned char); 38861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti meta = (struct enc_meta_out *)src; 38961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti while (num_of_frames > 0) { 39061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti meta = (struct enc_meta_out *)src; 39161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti /*printf("offset=%d framesize=%d encoded_pcm[%d] msw_ts[%d]lsw_ts[%d] nflags[%d]\n", 39261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti meta->offset_to_frame, 39361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti meta->frame_size, 39461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti meta->encoded_pcm_samples, meta->msw_ts, meta->lsw_ts, meta->nflags);*/ 39561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti len = meta->frame_size; 39661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 39761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti bytes_writen = fwrite(pBuffer->pBuffer + sizeof(unsigned char) + meta->offset_to_frame,1,len,outputBufferFile); 39861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if(bytes_writen < len) 39961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti { 40061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("error: invalid AMR encoded data \n"); 40161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti return OMX_ErrorNone; 40261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 40361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti src += sizeof(struct enc_meta_out); 40461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti num_of_frames--; 40561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti total_bytes_writen += len; 40661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 40761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT(" FillBufferDone size writen to file %zu count %d\n",total_bytes_writen, framecnt); 40861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti totaldatalen = totaldatalen + (int)total_bytes_writen; 40961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti framecnt++; 41061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 41161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT(" FBD calling FTB\n"); 41261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti OMX_FillThisBuffer(hComponent,pBuffer); 41361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 41461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti return OMX_ErrorNone; 41561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti} 41661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 41761e21a4fe27118141afc13323807f83b733cf426Uday Kishore PasupuletiOMX_ERRORTYPE EmptyBufferDone(OMX_IN OMX_HANDLETYPE hComponent, 41861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti OMX_IN OMX_PTR pAppData, 41961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti OMX_IN OMX_BUFFERHEADERTYPE* pBuffer) 42061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti{ 42161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti int readBytes =0; 42261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti /* To remove warning for unused variable to keep prototype same */ 42361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti (void)pAppData; 42461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 42561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti ebd_cnt++; 42661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti used_ip_buf_cnt--; 42761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti pthread_mutex_lock(&etb_lock); 42861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if(!etb_done) 42961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti { 43061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("\n*********************************************\n"); 43161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("Wait till first set of buffers are given to component\n"); 43261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("\n*********************************************\n"); 43361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti etb_done++; 43461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti pthread_mutex_unlock(&etb_lock); 43561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti etb_wait_for_event(); 43661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 43761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti else 43861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti { 43961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti pthread_mutex_unlock(&etb_lock); 44061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 44161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 44261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 44361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if(bInputEosReached) 44461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti { 44561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("\n*********************************************\n"); 44661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT(" EBD::EOS on input port\n "); 44761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("*********************************************\n"); 44861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti return OMX_ErrorNone; 44961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti }else if (bFlushing == true) { 45061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("omx_amr_adec_test: bFlushing is set to TRUE used_ip_buf_cnt=%d\n",used_ip_buf_cnt); 45161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if (used_ip_buf_cnt == 0) { 45261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti bFlushing = false; 45361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } else { 45461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("omx_amr_adec_test: more buffer to come back used_ip_buf_cnt=%d\n",used_ip_buf_cnt); 45561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti return OMX_ErrorNone; 45661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 45761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 45861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 45961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if((readBytes = Read_Buffer(pBuffer)) > 0) { 46061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti pBuffer->nFilledLen = (OMX_U32)readBytes; 46161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti used_ip_buf_cnt++; 46261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti OMX_EmptyThisBuffer(hComponent,pBuffer); 46361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 46461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti else{ 46561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti pBuffer->nFlags |= OMX_BUFFERFLAG_EOS; 46661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti used_ip_buf_cnt++; 46761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti bInputEosReached = true; 46861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti pBuffer->nFilledLen = 0; 46961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti OMX_EmptyThisBuffer(hComponent,pBuffer); 47061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("EBD..Either EOS or Some Error while reading file\n"); 47161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 47261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti return OMX_ErrorNone; 47361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti} 47461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 47561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletivoid signal_handler(int sig_id) { 47661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 47761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti /* Flush */ 47861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if (sig_id == SIGUSR1) { 47961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("%s Initiate flushing\n", __FUNCTION__); 48061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti bFlushing = true; 48161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti OMX_SendCommand(amr_enc_handle, OMX_CommandFlush, OMX_ALL, NULL); 48261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } else if (sig_id == SIGUSR2) { 48361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if (bPause == true) { 48461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("%s resume record\n", __FUNCTION__); 48561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti bPause = false; 48661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti OMX_SendCommand(amr_enc_handle, OMX_CommandStateSet, OMX_StateExecuting, NULL); 48761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } else { 48861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("%s pause record\n", __FUNCTION__); 48961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti bPause = true; 49061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti OMX_SendCommand(amr_enc_handle, OMX_CommandStateSet, OMX_StatePause, NULL); 49161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 49261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 49361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti} 49461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 49561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletiint main(int argc, char **argv) 49661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti{ 49761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti unsigned int bufCnt=0; 49861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti OMX_ERRORTYPE result; 49961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 50061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti struct sigaction sa; 50161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti char amr_header[6] = {0x23, 0x21, 0x41, 0x4D, 0x52, 0x0A}; 50261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti memset(&sa, 0, sizeof(sa)); 50361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti sa.sa_handler = &signal_handler; 50461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti sigaction(SIGABRT, &sa, NULL); 50561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti sigaction(SIGUSR1, &sa, NULL); 50661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti sigaction(SIGUSR2, &sa, NULL); 50761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 50861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti (void) signal(SIGINT, Release_Encoder); 50961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 51061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti pthread_cond_init(&cond, 0); 51161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti pthread_mutex_init(&lock, 0); 51261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti pthread_cond_init(&etb_cond, 0); 51361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti pthread_mutex_init(&etb_lock, 0); 51461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti pthread_mutex_init(&etb_lock1, 0); 51561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 51661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if (argc >= 8) { 51761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti in_filename = argv[1]; 51861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti out_filename = argv[2]; 51961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti tunnel = (uint32_t)atoi(argv[3]); 52061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti bandmode = (uint32_t)atoi(argv[4]); 52161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti dtxenable = (uint32_t)atoi(argv[5]); 52261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti recpath = (uint32_t)atoi(argv[6]); // No configuration support yet.. 52361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti rectime = (uint32_t)atoi(argv[7]); 52461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 52561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } else { 52661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT(" invalid format: \n"); 52761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("ex: ./mm-aenc-omxamr-test INPUTFILE OUTPUTFILE Tunnel BANDMODE DTXENABLE RECORDPATH RECORDTIME\n"); 52861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("Bandmode 1-7, dtxenable 0-1\n"); 52961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("RECORDPATH 0(TX),1(RX),2(BOTH),3(MIC)\n"); 53061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("RECORDTIME in seconds for AST Automation\n"); 53161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti return 0; 53261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 53361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if(recpath != 3) { 53461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("For RECORDPATH Only MIC supported\n"); 53561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti return 0; 53661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 53761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if(tunnel == 0) 53861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti aud_comp = "OMX.qcom.audio.encoder.amrnb"; 53961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti else 54061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti aud_comp = "OMX.qcom.audio.encoder.tunneled.amrnb"; 54161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if(Init_Encoder(aud_comp)!= 0x00) 54261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti { 54361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("Decoder Init failed\n"); 54461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti return -1; 54561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 54661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 54761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti fcntl(0, F_SETFL, O_NONBLOCK); 54861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 54961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if(Play_Encoder() != 0x00) 55061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti { 55161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("Play_Decoder failed\n"); 55261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti return -1; 55361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 55461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 55561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti // Wait till EOS is reached... 55661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if(rectime && tunnel) 55761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti { 55861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti sleep(rectime); 55961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti rectime = 0; 56061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti bInputEosReached_tunnel = 1; 56161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("\EOS ON INPUT PORT\n"); 56261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 56361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti else 56461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti { 56561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti wait_for_event(); 56661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 56761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 56861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if((bInputEosReached_tunnel) || ((bOutputEosReached) && !tunnel)) 56961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti { 57061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 57161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("\nMoving the decoder to idle state \n"); 57261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti OMX_SendCommand(amr_enc_handle, OMX_CommandStateSet, OMX_StateIdle,0); 57361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti wait_for_event(); 57461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 57561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("\nMoving the encoder to loaded state \n"); 57661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti OMX_SendCommand(amr_enc_handle, OMX_CommandStateSet, OMX_StateLoaded,0); 57761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti sleep(1); 57861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if (!tunnel) 57961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti { 58061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("\nFillBufferDone: Deallocating i/p buffers \n"); 58161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti for(bufCnt=0; bufCnt < input_buf_cnt; ++bufCnt) { 58261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti OMX_FreeBuffer(amr_enc_handle, 0, pInputBufHdrs[bufCnt]); 58361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 58461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 58561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 58661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT ("\nFillBufferDone: Deallocating o/p buffers \n"); 58761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti for(bufCnt=0; bufCnt < output_buf_cnt; ++bufCnt) { 58861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti OMX_FreeBuffer(amr_enc_handle, 1, pOutputBufHdrs[bufCnt]); 58961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 59061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti wait_for_event(); 59161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti fseek(outputBufferFile, 0,SEEK_SET); 59261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti fwrite(amr_header,1,AMR_HEADER_SIZE,outputBufferFile); 59361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 59461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti result = OMX_FreeHandle(amr_enc_handle); 59561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if (result != OMX_ErrorNone) { 59661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT ("\nOMX_FreeHandle error. Error code: %d\n", result); 59761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 59861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 59961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti /* Deinit OpenMAX */ 60061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if(tunnel) 60161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti { 60261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti #ifdef AUDIOV2 60361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if (msm_route_stream(DIR_TX,session_id,device_id, 0)) 60461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti { 60561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("\ncould not set stream routing\n"); 60661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti return -1; 60761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 60861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if (msm_en_device(device_id, 0)) 60961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti { 61061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("\ncould not enable device\n"); 61161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti return -1; 61261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 61361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti msm_mixer_close(); 61461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti #endif 61561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 61661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti OMX_Deinit(); 61761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti ebd_cnt=0; 61861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti bOutputEosReached = false; 61961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti bInputEosReached_tunnel = false; 62061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti bInputEosReached = 0; 62161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti amr_enc_handle = NULL; 62261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti pthread_cond_destroy(&cond); 62361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti pthread_mutex_destroy(&lock); 62461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti fclose(outputBufferFile); 62561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("*****************************************\n"); 62661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("******...AMR ENC TEST COMPLETED...***************\n"); 62761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("*****************************************\n"); 62861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 62961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti return 0; 63061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti} 63161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 63261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletivoid Release_Encoder() 63361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti{ 63461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti static int cnt=0; 63561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti OMX_ERRORTYPE result; 63661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 63761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("END OF AMR ENCODING: EXITING PLEASE WAIT\n"); 63861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti bInputEosReached_tunnel = 1; 63961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti event_complete(); 64061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti cnt++; 64161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if(cnt > 1) 64261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti { 64361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti /* FORCE RESET */ 64461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti amr_enc_handle = NULL; 64561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti ebd_cnt=0; 64661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti bInputEosReached_tunnel = false; 64761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 64861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti result = OMX_FreeHandle(amr_enc_handle); 64961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if (result != OMX_ErrorNone) { 65061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT ("\nOMX_FreeHandle error. Error code: %d\n", result); 65161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 65261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 65361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti /* Deinit OpenMAX */ 65461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 65561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti OMX_Deinit(); 65661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 65761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti pthread_cond_destroy(&cond); 65861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti pthread_mutex_destroy(&lock); 65961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("*****************************************\n"); 66061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("******...AMR ENC TEST COMPLETED...***************\n"); 66161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("*****************************************\n"); 66261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti exit(0); 66361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 66461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti} 66561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 66661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletiint Init_Encoder(OMX_STRING audio_component) 66761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti{ 66861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("Inside %s \n", __FUNCTION__); 66961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti OMX_ERRORTYPE omxresult; 67061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti OMX_U32 total = 0; 67161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti typedef OMX_U8* OMX_U8_PTR; 67261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti char *role ="audio_encoder"; 67361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 67461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti static OMX_CALLBACKTYPE call_back = { 67561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti &EventHandler,&EmptyBufferDone,&FillBufferDone 67661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti }; 67761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 67861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti /* Init. the OpenMAX Core */ 67961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("\nInitializing OpenMAX Core....\n"); 68061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti omxresult = OMX_Init(); 68161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 68261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if(OMX_ErrorNone != omxresult) { 68361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("\n Failed to Init OpenMAX core"); 68461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti return -1; 68561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 68661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti else { 68761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("\nOpenMAX Core Init Done\n"); 68861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 68961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 69061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti /* Query for audio decoders*/ 69161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("Amr_test: Before entering OMX_GetComponentOfRole"); 69261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti OMX_GetComponentsOfRole(role, &total, 0); 69361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT ("\nTotal components of role=%s :%u", role, total); 69461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 69561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 69661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti omxresult = OMX_GetHandle((OMX_HANDLETYPE*)(&amr_enc_handle), 69761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti (OMX_STRING)audio_component, NULL, &call_back); 69861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if (FAILED(omxresult)) { 69961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("\nFailed to Load the component:%s\n", audio_component); 70061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti return -1; 70161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 70261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti else 70361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti { 70461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("\nComponent %s is in LOADED state\n", audio_component); 70561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 70661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 70761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti /* Get the port information */ 70861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti CONFIG_VERSION_SIZE(portParam); 70961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti omxresult = OMX_GetParameter(amr_enc_handle, OMX_IndexParamAudioInit, 71061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti (OMX_PTR)&portParam); 71161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 71261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if(FAILED(omxresult)) { 71361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("\nFailed to get Port Param\n"); 71461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti return -1; 71561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 71661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti else 71761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti { 71861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("\nportParam.nPorts:%u\n", portParam.nPorts); 71961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("\nportParam.nStartPortNumber:%u\n", 72061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti portParam.nStartPortNumber); 72161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 72261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 72361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if(OMX_ErrorNone != omxresult) 72461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti { 72561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("Set parameter failed"); 72661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 72761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 72861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti return 0; 72961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti} 73061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 73161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletiint Play_Encoder() 73261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti{ 73361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti unsigned int i; 73461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti int Size=0; 73561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("Inside %s \n", __FUNCTION__); 73661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti OMX_ERRORTYPE ret; 73761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti OMX_INDEXTYPE index; 73861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti#ifdef __LP64__ 73961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("sizeof[%ld]\n", sizeof(OMX_BUFFERHEADERTYPE)); 74061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti#else 74161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("sizeof[%d]\n", sizeof(OMX_BUFFERHEADERTYPE)); 74261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti#endif 74361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 74461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti /* open the i/p and o/p files based on the video file format passed */ 74561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if(open_audio_file()) { 74661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("\n Returning -1"); 74761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti return -1; 74861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 74961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 75061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti /* Query the encoder input min buf requirements */ 75161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti CONFIG_VERSION_SIZE(inputportFmt); 75261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 75361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti /* Port for which the Client needs to obtain info */ 75461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti inputportFmt.nPortIndex = portParam.nStartPortNumber; 75561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 75661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti OMX_GetParameter(amr_enc_handle,OMX_IndexParamPortDefinition,&inputportFmt); 75761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT ("\nEnc Input Buffer Count %u\n", inputportFmt.nBufferCountMin); 75861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT ("\nEnc: Input Buffer Size %u\n", inputportFmt.nBufferSize); 75961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 76061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if(OMX_DirInput != inputportFmt.eDir) { 76161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT ("\nEnc: Expect Input Port\n"); 76261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti return -1; 76361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 76461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 76561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti pcmparam.nPortIndex = 0; 76661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti pcmparam.nChannels = channels; 76761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti pcmparam.nSamplingRate = samplerate; 76861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti OMX_SetParameter(amr_enc_handle,OMX_IndexParamAudioPcm,&pcmparam); 76961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 77061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 77161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti /* Query the encoder outport's min buf requirements */ 77261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti CONFIG_VERSION_SIZE(outputportFmt); 77361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti /* Port for which the Client needs to obtain info */ 77461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti outputportFmt.nPortIndex = portParam.nStartPortNumber + 1; 77561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 77661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti OMX_GetParameter(amr_enc_handle,OMX_IndexParamPortDefinition,&outputportFmt); 77761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT ("\nEnc: Output Buffer Count %u\n", outputportFmt.nBufferCountMin); 77861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT ("\nEnc: Output Buffer Size %u\n", outputportFmt.nBufferSize); 77961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 78061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if(OMX_DirOutput != outputportFmt.eDir) { 78161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT ("\nEnc: Expect Output Port\n"); 78261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti return -1; 78361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 78461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 78561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 78661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti CONFIG_VERSION_SIZE(amrparam); 78761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 78861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti amrparam.nPortIndex = 1; 78961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti amrparam.nChannels = channels; //2 ; /* 1-> mono 2-> stereo*/ 79061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti amrparam.eAMRBandMode = bandmode; 79161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti amrparam.eAMRDTXMode = dtxenable; 79261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti OMX_SetParameter(amr_enc_handle,OMX_IndexParamAudioAmr,&amrparam); 79361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti OMX_GetExtensionIndex(amr_enc_handle,"OMX.Qualcomm.index.audio.sessionId",&index); 79461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti OMX_GetParameter(amr_enc_handle,index,&streaminfoparam); 79561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if(tunnel) { 79661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti #ifdef AUDIOV2 79761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti session_id = streaminfoparam.sessionId; 79861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti control = msm_mixer_open("/dev/snd/controlC0", 0); 79961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if(control < 0) 80061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti printf("ERROR opening the device\n"); 80161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti device_id = msm_get_device(device); 80261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT ("\ndevice_id = %d\n",device_id); 80361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("\nsession_id = %d\n",session_id); 80461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if (msm_en_device(device_id, 1)) 80561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti { 80661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti perror("could not enable device\n"); 80761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti return -1; 80861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 80961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if (msm_route_stream(DIR_TX,session_id,device_id, 1)) 81061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti { 81161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti perror("could not set stream routing\n"); 81261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti return -1; 81361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 81461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti #endif 81561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 81661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 81761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT ("\nOMX_SendCommand Encoder -> IDLE\n"); 81861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti OMX_SendCommand(amr_enc_handle, OMX_CommandStateSet, OMX_StateIdle,0); 81961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti /* wait_for_event(); should not wait here event complete status will 82061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti not come until enough buffer are allocated */ 82161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if (tunnel == 0) 82261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti { 82361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti input_buf_cnt = inputportFmt.nBufferCountActual; // inputportFmt.nBufferCountMin + 5; 82461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("Transition to Idle State succesful...\n"); 82561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti /* Allocate buffer on decoder's i/p port */ 82661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti error = Allocate_Buffer(amr_enc_handle, &pInputBufHdrs, inputportFmt.nPortIndex, 82761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti input_buf_cnt, inputportFmt.nBufferSize); 82861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if (error != OMX_ErrorNone || pInputBufHdrs == NULL ) { 82961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT ("\nOMX_AllocateBuffer Input buffer error\n"); 83061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti return -1; 83161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 83261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti else { 83361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT ("\nOMX_AllocateBuffer Input buffer success\n"); 83461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 83561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 83661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti output_buf_cnt = outputportFmt.nBufferCountMin ; 83761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 83861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti /* Allocate buffer on encoder's O/Pp port */ 83961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti error = Allocate_Buffer(amr_enc_handle, &pOutputBufHdrs, outputportFmt.nPortIndex, 84061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti output_buf_cnt, outputportFmt.nBufferSize); 84161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if (error != OMX_ErrorNone || pOutputBufHdrs == NULL ) { 84261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT ("\nOMX_AllocateBuffer Output buffer error\n"); 84361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti return -1; 84461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 84561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti else { 84661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT ("\nOMX_AllocateBuffer Output buffer success\n"); 84761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 84861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 84961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti wait_for_event(); 85061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 85161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 85261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if (tunnel == 1) 85361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti { 85461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT ("\nOMX_SendCommand to enable TUNNEL MODE during IDLE\n"); 85561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti OMX_SendCommand(amr_enc_handle, OMX_CommandPortDisable,0,0); // disable input port 85661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti wait_for_event(); 85761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 85861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 85961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT ("\nOMX_SendCommand encoder -> Executing\n"); 86061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti OMX_SendCommand(amr_enc_handle, OMX_CommandStateSet, OMX_StateExecuting,0); 86161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti wait_for_event(); 86261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 86361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT(" Start sending OMX_FILLthisbuffer\n"); 86461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 86561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti for(i=0; i < output_buf_cnt; i++) { 86661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT ("\nOMX_FillThisBuffer on output buf no.%d\n",i); 86761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti pOutputBufHdrs[i]->nOutputPortIndex = 1; 86861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti pOutputBufHdrs[i]->nFlags = pOutputBufHdrs[i]->nFlags & (unsigned)~OMX_BUFFERFLAG_EOS; 86961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti ret = OMX_FillThisBuffer(amr_enc_handle, pOutputBufHdrs[i]); 87061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if (OMX_ErrorNone != ret) { 87161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("OMX_FillThisBuffer failed with result %d\n", ret); 87261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 87361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti else { 87461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("OMX_FillThisBuffer success!\n"); 87561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 87661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 87761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 87861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletiif(tunnel == 0) 87961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti{ 88061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT(" Start sending OMX_emptythisbuffer\n"); 88161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti for (i = 0;i < input_buf_cnt;i++) { 88261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT ("\nOMX_EmptyThisBuffer on Input buf no.%d\n",i); 88361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti pInputBufHdrs[i]->nInputPortIndex = 0; 88461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti Size = Read_Buffer(pInputBufHdrs[i]); 88561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if(Size <=0 ){ 88661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("NO DATA READ\n"); 88761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti bInputEosReached = true; 88861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti pInputBufHdrs[i]->nFlags= OMX_BUFFERFLAG_EOS; 88961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 89061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti pInputBufHdrs[i]->nFilledLen = (OMX_U32)Size; 89161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti pInputBufHdrs[i]->nInputPortIndex = 0; 89261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti used_ip_buf_cnt++; 89361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti ret = OMX_EmptyThisBuffer(amr_enc_handle, pInputBufHdrs[i]); 89461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if (OMX_ErrorNone != ret) { 89561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("OMX_EmptyThisBuffer failed with result %d\n", ret); 89661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 89761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti else { 89861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("OMX_EmptyThisBuffer success!\n"); 89961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 90061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if(Size <=0 ){ 90161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti break;//eos reached 90261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 90361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 90461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti pthread_mutex_lock(&etb_lock); 90561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if(etb_done) 90661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti{ 90761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("Component is waiting for EBD to be released.\n"); 90861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti etb_event_complete(); 90961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 91061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti else 91161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti { 91261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("\n****************************\n"); 91361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("EBD not yet happened ...\n"); 91461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("\n****************************\n"); 91561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti etb_done++; 91661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 91761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti pthread_mutex_unlock(&etb_lock); 91861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti} 91961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 92061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti return 0; 92161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti} 92261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 92361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 92461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 92561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletistatic OMX_ERRORTYPE Allocate_Buffer ( OMX_COMPONENTTYPE *avc_enc_handle, 92661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti OMX_BUFFERHEADERTYPE ***pBufHdrs, 92761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti OMX_U32 nPortIndex, 92861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti unsigned int bufCntMin, unsigned int bufSize) 92961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti{ 93061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("Inside %s \n", __FUNCTION__); 93161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti OMX_ERRORTYPE error=OMX_ErrorNone; 93261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti unsigned int bufCnt=0; 93361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 93461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti /* To remove warning for unused variable to keep prototype same */ 93561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti (void)avc_enc_handle; 93661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti *pBufHdrs= (OMX_BUFFERHEADERTYPE **) 93761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti malloc(sizeof(OMX_BUFFERHEADERTYPE*)*bufCntMin); 93861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 93961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti for(bufCnt=0; bufCnt < bufCntMin; ++bufCnt) { 94061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("\n OMX_AllocateBuffer No %d \n", bufCnt); 94161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti error = OMX_AllocateBuffer(amr_enc_handle, &((*pBufHdrs)[bufCnt]), 94261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti nPortIndex, NULL, bufSize); 94361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 94461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 94561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti return error; 94661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti} 94761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 94861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 94961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 95061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 95161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletistatic int Read_Buffer (OMX_BUFFERHEADERTYPE *pBufHdr ) 95261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti{ 95361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 95461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti size_t bytes_read=0; 95561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 95661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 95761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti pBufHdr->nFilledLen = 0; 95861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti pBufHdr->nFlags |= OMX_BUFFERFLAG_EOS; 95961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 96061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti bytes_read = fread(pBufHdr->pBuffer, 1, pBufHdr->nAllocLen , inputBufferFile); 96161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 96261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti pBufHdr->nFilledLen = (OMX_U32)bytes_read; 96361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti // Time stamp logic 96461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti ((OMX_BUFFERHEADERTYPE *)pBufHdr)->nTimeStamp = \ 96561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 96661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti (OMX_TICKS) ((total_pcm_bytes * 1000)/(samplerate * channels *2)); 96761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 96861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT ("\n--time stamp -- %ld\n", (unsigned long)((OMX_BUFFERHEADERTYPE *)pBufHdr)->nTimeStamp); 96961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if(bytes_read == 0) 97061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti { 97161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti pBufHdr->nFlags |= OMX_BUFFERFLAG_EOS; 97261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT ("\nBytes read zero\n"); 97361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 97461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti else 97561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti { 97661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti pBufHdr->nFlags = pBufHdr->nFlags & (unsigned)~OMX_BUFFERFLAG_EOS; 97761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 97861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti total_pcm_bytes = (unsigned)(total_pcm_bytes + bytes_read); 97961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 98061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 98161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti return (int)bytes_read;; 98261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti} 98361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 98461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 98561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 98661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti//In Encoder this Should Open a PCM or WAV file for input. 98761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 98861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletistatic int open_audio_file () 98961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti{ 99061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti int error_code = 0; 99161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 99261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if (!tunnel) 99361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti { 99461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("Inside %s filename=%s\n", __FUNCTION__, in_filename); 99561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti inputBufferFile = fopen (in_filename, "rb"); 99661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if (inputBufferFile == NULL) { 99761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("\ni/p file %s could NOT be opened\n", 99861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti in_filename); 99961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti error_code = -1; 100061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 100161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if(parse_pcm_header() != 0x00) 100261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti { 100361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("PCM parser failed \n"); 100461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti return -1; 100561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 100661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 100761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 100861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("Inside %s filename=%s\n", __FUNCTION__, out_filename); 100961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti outputBufferFile = fopen (out_filename, "wb"); 101061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if (outputBufferFile == NULL) { 101161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("\ni/p file %s could NOT be opened\n", 101261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti out_filename); 101361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti error_code = -1; 101461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti return error_code; 101561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 101661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti fseek(outputBufferFile, AMR_HEADER_SIZE, SEEK_SET); 101761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti return error_code; 101861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti} 101961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 102061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuletistatic OMX_ERRORTYPE parse_pcm_header() 102161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti{ 102261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti struct wav_header hdr; 102361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 102461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("\n***************************************************************\n"); 102561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if(fread(&hdr, 1, sizeof(hdr),inputBufferFile)!=sizeof(hdr)) 102661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti { 102761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("Wav file cannot read header\n"); 102861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti return -1; 102961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 103061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 103161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if ((hdr.riff_id != ID_RIFF) || 103261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti (hdr.riff_fmt != ID_WAVE)|| 103361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti (hdr.fmt_id != ID_FMT)) 103461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti { 103561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("Wav file is not a riff/wave file\n"); 103661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti return -1; 103761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 103861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 103961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti if (hdr.audio_format != FORMAT_PCM) 104061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti { 104161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("Wav file is not adpcm format %d and fmt size is %d\n", 104261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti hdr.audio_format, hdr.fmt_sz); 104361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti return -1; 104461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti } 104561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 104661e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("Samplerate is %d\n", hdr.sample_rate); 104761e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("Channel Count is %d\n", hdr.num_channels); 104861e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti DEBUG_PRINT("\n***************************************************************\n"); 104961e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 105061e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti samplerate = hdr.sample_rate; 105161e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti channels = hdr.num_channels; 105261e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti total_pcm_bytes = 0; 105361e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti 105461e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti return OMX_ErrorNone; 105561e21a4fe27118141afc13323807f83b733cf426Uday Kishore Pasupuleti} 1056