2 Copyright 2004-2005 Chris Tallon, 2009 Marten Richter
4 This file is part of VOMP.
6 VOMP is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 VOMP is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with VOMP; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 #include "woptionpane.h"
33 lastAType = MPTYPE_MPEG_AUDIO;
38 canpass_pcm_mch=false;
40 prefered_ac3=0; //0 stereo PCM, 1 passthrough 2 Multichannel PCM
47 omx_aud_rend/*dec*/=0;
48 cur_input_buf_omx=NULL;
51 ac3codec_context_libav=NULL;
54 mp23codec_context_libav=NULL;
62 int AudioOMX::init(UCHAR tstreamType) {
67 streamType = tstreamType;
69 if (!initAllParams()) {
79 av_log_set_flags(AV_LOG_SKIP_REPEATED);
81 ac3codec_libav = avcodec_find_decoder(CODEC_ID_AC3);
82 if (ac3codec_libav == NULL) {
83 Log::getInstance()->log("Audio", Log::DEBUG,
84 "Find libav ac3 decoder failed");
88 mp23codec_libav = avcodec_find_decoder(CODEC_ID_MP3);
89 if (mp23codec_libav == NULL) {
90 Log::getInstance()->log("Audio", Log::DEBUG,
91 "Find libav mpeg audio decoder failed");
98 int AudioOMX::initAllParams()
100 return (setStreamType(streamType) && setChannel() && setSource());
103 int AudioOMX::shutdown()
105 if (!initted) return 0;
108 Log::getInstance()->log("Audio", Log::DEBUG, "audio shutdown called");
109 DeAllocateCodecsOMX();
114 bool AudioOMX::loadOptionsfromServer(VDR* vdr)
116 Log::getInstance()->log("Audio", Log::DEBUG, "AudioOMX config load");
117 char *name=vdr->configLoad("AudioOMX","AC3DecodingMode");
120 if (STRCASECMP(name, "PCM") == 0) {
122 } else if (STRCASECMP(name, "Passthrough") == 0) {
124 } else if (STRCASECMP(name, "PCMMultichannel") == 0) {
129 name = vdr->configLoad("AudioOMX", "Mp2DecodingMode");
132 if (STRCASECMP(name, "PCM") == 0) {
134 } else if (STRCASECMP(name, "Passthrough") == 0) {
136 } else if (STRCASECMP(name, "PCMMultichannel") == 0) {
141 name = vdr->configLoad("AudioOMX", "Mp3DecodingMode");
144 if (STRCASECMP(name, "PCM") == 0) {
146 } else if (STRCASECMP(name, "Passthrough") == 0) {
148 } else if (STRCASECMP(name, "PCMMultichannel") == 0) {
153 name = vdr->configLoad("AudioOMX", "AudioOutput");
156 if (STRCASECMP(name, "analog") == 0) {
158 } else if (STRCASECMP(name, "HDMI") == 0) {
168 bool AudioOMX::handleOptionChanges(Option* option)
170 if (Audio::handleOptionChanges(option))
172 switch (option->id) {
174 if (STRCASECMP(option->options[option->userSetChoice], "analog") == 0) {
176 } else if (STRCASECMP(option->options[option->userSetChoice], "HDMI")
184 if (STRCASECMP(option->options[option->userSetChoice], "PCM") == 0) {
186 } else if (STRCASECMP(option->options[option->userSetChoice],
187 "Passthrough") == 0) {
189 } else if (STRCASECMP(option->options[option->userSetChoice],
190 "PCMMultichannel") == 0) {
196 if (STRCASECMP(option->options[option->userSetChoice], "PCM") == 0) {
198 } else if (STRCASECMP(option->options[option->userSetChoice],
199 "Passthrough") == 0) {
201 } else if (STRCASECMP(option->options[option->userSetChoice],
202 "PCMMultichannel") == 0) {
208 if (STRCASECMP(option->options[option->userSetChoice], "PCM") == 0) {
210 } else if (STRCASECMP(option->options[option->userSetChoice],
211 "Passthrough") == 0) {
213 } else if (STRCASECMP(option->options[option->userSetChoice],
214 "PCMMultichannel") == 0) {
224 bool AudioOMX::saveOptionstoServer()
227 switch (prefered_ac3) {
229 VDR::getInstance()->configSave("AudioOMX", "AC3DecodingMode", "PCM");
232 VDR::getInstance()->configSave("AudioOMX", "AC3DecodingMode",
236 VDR::getInstance()->configSave("AudioOMX", "AC3DecodingMode",
241 switch (prefered_mp2) {
243 VDR::getInstance()->configSave("AudioOMX", "Mp2DecodingMode", "PCM");
246 VDR::getInstance()->configSave("AudioOMX", "Mp2DecodingMode",
250 VDR::getInstance()->configSave("AudioOMX", "Mp2DecodingMode",
255 switch (prefered_mp3) {
257 VDR::getInstance()->configSave("AudioOMX", "Mp3DecodingMode", "PCM");
260 VDR::getInstance()->configSave("AudioOMX", "Mp3DecodingMode",
264 VDR::getInstance()->configSave("AudioOMX", "Mp3DecodingMode",
270 VDR::getInstance()->configSave("AudioOMX", "AudioOutput", "analog");
272 VDR::getInstance()->configSave("AudioOMX", "AudioOutput", "HDMI");
278 /*Option(UINT id, const char* displayText, const char* configSection, const char* configKey, UINT optionType,
279 UINT numChoices, UINT defaultChoice, UINT startInt,
280 const char * const * options, const char * const * optionkeys = NULL, AbstractOption* handler=NULL);*/
282 bool AudioOMX::addOptionsToPanes(int panenumber,Options *options,WOptionPane* pane)
284 if (!Audio::addOptionsToPanes(panenumber,options,pane)) return false;
291 static const char* audioopts[]={"analog","HDMI"};
292 option = new Option(4,tr("Audio Output"), "AudioOMX","AudioOutput",Option::TYPE_TEXT,2,0,0,audioopts,NULL,false,this);
293 options->push_back(option);
294 pane->addOptionLine(option);
297 char **ac3opts=new char *[3];
299 ac3opts[i]=new char[strlen("PCM")+1];
300 strcpy(ac3opts[i],"PCM");
303 ac3opts[i]=new char[strlen("Passthrough")+1];
304 strcpy(ac3opts[i],"PassThrough");
307 if (canpass_pcm_mch) {
308 ac3opts[i]=new char[strlen("PCMMultichannel")+1];
309 strcpy(ac3opts[i],"PCMMultichannel");
312 option = new Option(1 ,tr("AC3 HDMI Mode"), "AudioOMX", "AC3DecodingMode", Option::TYPE_TEXT, i, 0, 0, ac3opts,NULL,true, this);
313 options->push_back(option);
314 pane->addOptionLine(option);
316 char **mp2opts = new char *[3];
318 mp2opts[i] = new char[strlen("PCM") + 1];
319 strcpy(mp2opts[i], "PCM");
322 mp2opts[i] = new char[strlen("Passthrough") + 1];
323 strcpy(mp2opts[i], "PassThrough");
326 if (canpass_pcm_mch) {
327 mp2opts[i] = new char[strlen("PCMMultichannel") + 1];
328 strcpy(mp2opts[i], "PCMMultichannel");
331 option = new Option(2, tr("Mp2 HDMI Mode"), "AudioOMX",
332 "Mp2DecodingMode", Option::TYPE_TEXT, i, 0, 0,
333 mp2opts, NULL, true, this);
334 options->push_back(option);
335 pane->addOptionLine(option);
337 char **mp3opts = new char *[3];
339 mp3opts[i] = new char[strlen("PCM") + 1];
340 strcpy(mp3opts[i], "PCM");
343 mp3opts[i] = new char[strlen("Passthrough") + 1];
344 strcpy(mp3opts[i], "PassThrough");
347 if (canpass_pcm_mch) {
348 mp3opts[i] = new char[strlen("PCMMultichannel") + 1];
349 strcpy(mp3opts[i], "PCMMultichannel");
352 option = new Option(3, tr("Mp3 HDMI Mode"), "AudioOMX",
353 "Mp2DecodingMode", Option::TYPE_TEXT, i, 0, 0, mp3opts,
355 options->push_back(option);
356 pane->addOptionLine(option);
369 OMX_ERRORTYPE AudioOMX::EmptyBufferDone_OMX(OMX_IN OMX_HANDLETYPE hcomp,OMX_IN OMX_PTR appdata,OMX_IN OMX_BUFFERHEADERTYPE* buffer){
371 //Log::getInstance()->log("Audio", Log::NOTICE, "EmptyBufferDone");
372 AudioOMX *audio=(AudioOMX *)getInstance();
373 audio->ReturnEmptyOMXBuffer(buffer);
374 return OMX_ErrorNone;
378 void AudioOMX::ReturnEmptyOMXBuffer(OMX_BUFFERHEADERTYPE* buffer){
379 input_bufs_omx_mutex.Lock();
380 //Log::getInstance()->log("Audio", Log::NOTICE, "ReturnEmptyOMXBuffer %d",input_bufs_omx_free.size());
381 input_bufs_omx_free.push_back(buffer);
382 //Log::getInstance()->log("Audio", Log::NOTICE, "ReturnEmptyOMXBuffer %d",input_bufs_omx_free.size());
383 input_bufs_omx_mutex.Unlock();
386 OMX_ERRORTYPE AudioOMX::FillBufferDone_OMX(OMX_IN OMX_HANDLETYPE hcomp, OMX_IN OMX_PTR appdata,OMX_IN OMX_BUFFERHEADERTYPE* buffer) {
387 Log::getInstance()->log("Audio", Log::NOTICE, "FillBufferDone");
388 return OMX_ErrorNone;
393 int AudioOMX::setStreamType(UCHAR type)
395 if (!initted) return 0;
397 // if (ioctl(fdAudio, AV_SET_AUD_STREAMTYPE, type) != 0) return 0;
401 int AudioOMX::setChannel()
403 if (!initted) return 0;
405 // if (ioctl(fdAudio, AV_SET_AUD_CHANNEL, 0) != 0) return 0;
409 int AudioOMX::setSource()
411 if (!initted) return 0;
413 // if (ioctl(fdAudio, AV_SET_AUD_SRC, 1) != 0) return 0;
419 if (!initted) return 0;
421 // if (ioctl(fdAudio, AV_SET_AUD_SYNC, 2) != 0) return 0;
425 int AudioOMX::play() {
428 lastAType=MPTYPE_MPEG_AUDIO;
429 Log::getInstance()->log("Audio", Log::DEBUG, "enter play");
431 if (!AllocateCodecsOMX()) {
438 int AudioOMX::ChangeAudioDestination() //clock aka omx mutex needs to be locked
441 const char * destinations[]={"local","hdmi"};
446 OMX_CONFIG_BRCMAUDIODESTINATIONTYPE auddest;
447 memset(&auddest,0,sizeof(auddest));
448 auddest.nSize=sizeof(auddest);
449 auddest.nVersion.nVersion=OMX_VERSION;
450 strcpy((char *)auddest.sName, destinations[dest]);
452 Log::getInstance()->log("Audio", Log::DEBUG, "setting destination to: %s",auddest.sName);
453 error=OMX_SetConfig(omx_aud_rend,OMX_IndexConfigBrcmAudioDestination,&auddest);
454 if (error!=OMX_ErrorNone){
455 Log::getInstance()->log("Audio", Log::DEBUG, "Init OMX_IndexConfigBrcmAudioDestination failed %x %x %s", error,omx_aud_rend,auddest.sName);
456 DeAllocateCodecsOMX();
464 int AudioOMX::ChangeAudioPortConfig() //clock aka omx mutex needs to be locked
467 //Ok first fidle a working configuration
468 Log::getInstance()->log("Audio", Log::DEBUG,
469 "ChangeAudioPortConfig");
473 case MPTYPE_MPEG_AUDIO: {
474 if (prefered_mp2 == 3 && false) { //not supported yet
477 if (prefered_mp2 == 2 && canpass_mp2) {
484 case MPTYPE_AC3_PRE13:
486 if (prefered_ac3 == 3 && false) { //not supported yet
489 if (prefered_ac3 == 2 && canpass_ac3) {
496 case MPTYPE_MPEG_AUDIO_LAYER3: {
497 if (prefered_mp3 == 3 && false) { //not supported yet
500 if (prefered_mp3 == 2 && canpass_mp2) {
510 //mch=false; // multichannel also false
515 /*OMX_CONFIG_BOOLEANTYPE booly;
516 memset(&booly, 0, sizeof(booly));
517 booly.nSize = sizeof(booly);
518 booly.nVersion.nVersion = OMX_VERSION;
520 booly.bEnabled = OMX_TRUE;
522 booly.bEnabled = OMX_FALSE;
524 error = OMX_SetParameter(omx_aud_dec, OMX_IndexParamBrcmDecoderPassThrough,
526 if (error != OMX_ErrorNone) {
527 Log::getInstance()->log("Audio", Log::DEBUG,
528 "Init OMX_IndexParamBrcmDecoderPassThrough failed %x", error);
529 DeAllocateCodecsOMX();
532 VideoOMX *video=(VideoOMX*)Video::getInstance();
540 OMX_AUDIO_PARAM_PCMMODETYPE audio_pcm;
541 memset(&audio_pcm, 0, sizeof(audio_pcm));
542 audio_pcm.nSize = sizeof(audio_pcm);
543 audio_pcm.nVersion.nVersion = OMX_VERSION;
544 audio_pcm.nChannels = 2;
545 audio_pcm.eChannelMapping[0] = OMX_AUDIO_ChannelLF;
546 audio_pcm.eChannelMapping[1] = OMX_AUDIO_ChannelRF;
547 //audio_pcm.eChannelMapping[2]=OMX_AUDIO_ChannelMax;
548 audio_pcm.eNumData = OMX_NumericalDataSigned;
549 audio_pcm.eEndian = OMX_EndianLittle;
550 audio_pcm.bInterleaved = OMX_TRUE;
551 audio_pcm.nBitPerSample = 16;
552 audio_pcm.ePCMMode = OMX_AUDIO_PCMModeLinear;
553 audio_pcm.nChannels = 2;
554 audio_pcm.nSamplingRate = 48000;
555 audio_pcm.nPortIndex = omx_rend_input_port;
556 error = OMX_SetParameter(omx_aud_rend, OMX_IndexParamAudioPcm,
558 if (error != OMX_ErrorNone) {
559 Log::getInstance()->log("Audio", Log::DEBUG,
560 "Init OMX_IndexParamAudioPcm failed %x %d", error,
561 omx_rend_input_port);
562 DeAllocateCodecsOMX();
576 int AudioOMX::InitDecoderLibAV()
579 ac3codec_context_libav = avcodec_alloc_context3(ac3codec_libav);
580 if (!ac3codec_context_libav) {
581 Log::getInstance()->log("Audio", Log::DEBUG, "Alloc avcodec for ac3 decoding context failed!");
585 ac3codec_context_libav->flags |= CODEC_FLAG_TRUNCATED;
586 ac3codec_context_libav->request_channels=2;
588 int avc_ret = avcodec_open2(ac3codec_context_libav, ac3codec_libav, NULL);
590 Log::getInstance()->log("Audio", Log::DEBUG, "Opening libav codec failed \n");
591 libav_mutex.Unlock();
595 mp23codec_context_libav = avcodec_alloc_context3(mp23codec_libav);
596 if (!ac3codec_context_libav) {
597 Log::getInstance()->log("Audio", Log::DEBUG, "Alloc avcodec for mp23 decoding context failed!");
598 libav_mutex.Unlock();
602 mp23codec_context_libav->flags |= CODEC_FLAG_TRUNCATED;
603 mp23codec_context_libav->request_channels=2;
605 avc_ret = avcodec_open2(mp23codec_context_libav, mp23codec_libav, NULL);
607 Log::getInstance()->log("Audio", Log::DEBUG, "Opening libav codec failed \n");
608 libav_mutex.Unlock();
612 av_init_packet(&incoming_paket_libav);
613 decode_frame_libav=avcodec_alloc_frame();
614 libav_mutex.Unlock();
621 void AudioOMX::DeinitDecoderLibAV() {
625 if (ac3codec_context_libav) {
626 avcodec_close(ac3codec_context_libav);
627 av_free(ac3codec_context_libav);
628 ac3codec_context_libav = NULL;
629 av_free(decode_frame_libav);
630 avcodec_close(mp23codec_context_libav);
631 av_free(mp23codec_context_libav);
632 mp23codec_context_libav = NULL;
635 libav_mutex.Unlock();
640 int AudioOMX::AllocateCodecsOMX()
643 static OMX_CALLBACKTYPE callbacks= {&VideoOMX::EventHandler_OMX,&EmptyBufferDone_OMX,&FillBufferDone_OMX};
645 Log::getInstance()->log("Audio", Log::NOTICE, "Allocate Codecs OMX");
646 //Clock, move later to audio
647 VideoOMX *video=(VideoOMX*)Video::getInstance();
649 if (!InitDecoderLibAV()) return 0;;
652 OMX_PORT_PARAM_TYPE p_param;
653 memset(&p_param,0,sizeof(p_param));
654 p_param.nSize=sizeof(p_param);
655 p_param.nVersion.nVersion=OMX_VERSION;
658 if (!video->getClockAudioandInit(&omx_clock,&omx_clock_output_port)){
659 return 0;// get the clock and init it if necessary
663 if (!video->idleClock()) {
668 error = OMX_GetHandle(&omx_aud_rend, VPE_OMX_AUDIO_REND, NULL, &callbacks);
669 if (error != OMX_ErrorNone) {
670 Log::getInstance()->log("Audio", Log::DEBUG,
671 "Init OMX audio rend failed %x", error);
672 video->UnlockClock();
673 DeAllocateCodecsOMX();
677 if (!ChangeAudioDestination()) {
678 video->UnlockClock();
679 DeAllocateCodecsOMX();
683 error = OMX_GetParameter(omx_aud_rend, OMX_IndexParamAudioInit, &p_param);
684 if (error != OMX_ErrorNone) {
685 Log::getInstance()->log("Audio", Log::DEBUG,
686 "Init OMX audio rend OMX_GetParameter failed %x", error);
687 video->UnlockClock();
688 DeAllocateCodecsOMX();
691 omx_rend_input_port = p_param.nStartPortNumber;
693 error = OMX_GetParameter(omx_aud_rend, OMX_IndexParamOtherInit, &p_param);
694 if (error != OMX_ErrorNone) {
695 Log::getInstance()->log("Audio", Log::DEBUG,
696 "Init OMX aud rend OMX_GetParameter failed %x", error);
697 video->UnlockClock();
698 DeAllocateCodecsOMX();
701 // buggy return value
702 omx_rend_clock_port = p_param.nStartPortNumber;
705 /* error=OMX_GetHandle(&omx_aud_dec,VPE_OMX_AUDIO_DECODER,NULL,&callbacks);
707 if (error!=OMX_ErrorNone){
708 Log::getInstance()->log("Audio", Log::DEBUG, "Init OMX audio decoder failed %x", error);
709 video->UnlockClock();
710 DeAllocateCodecsOMX();
714 error=OMX_GetParameter(omx_aud_dec,OMX_IndexParamAudioInit,&p_param);
715 if (error!=OMX_ErrorNone){
716 Log::getInstance()->log("Audio", Log::DEBUG, "Init OMX audio decoder OMX_GetParameter failed %x", error);
717 video->UnlockClock();
718 DeAllocateCodecsOMX();
721 omx_codec_input_port=p_param.nStartPortNumber;
722 omx_codec_output_port=p_param.nStartPortNumber+1;
724 if (!video->DisablePort(omx_aud_dec,omx_codec_input_port) || !video->DisablePort(omx_aud_dec,omx_codec_output_port)) {
725 Log::getInstance()->log("Audio", Log::DEBUG, "Disable Ports OMX audio decoder failed");
726 video->UnlockClock();
727 DeAllocateCodecsOMX();
734 if (!video->DisablePort(omx_aud_rend,omx_rend_input_port,true) ) {
735 Log::getInstance()->log("Audio", Log::DEBUG, "Disable Ports OMX audio rend failed %d",omx_rend_input_port);
736 video->UnlockClock();
737 DeAllocateCodecsOMX();
741 if ( !video->DisablePort(omx_aud_rend, omx_rend_clock_port, true)) {
742 Log::getInstance()->log("Audio", Log::DEBUG,
743 "Disable Ports OMX rend clock port failed %d",omx_rend_clock_port);
744 video->UnlockClock();
745 DeAllocateCodecsOMX();
755 error=OMX_SetupTunnel(omx_clock,omx_clock_output_port,omx_aud_rend,omx_rend_clock_port);
756 if (error!=OMX_ErrorNone){
757 Log::getInstance()->log("Audio", Log::DEBUG, "OMX_Setup tunnel clock to rend failed %x %d %d", error,omx_clock_output_port,omx_rend_clock_port);
758 video->UnlockClock();
759 DeAllocateCodecsOMX();
763 if (!video->EnablePort(omx_clock,omx_clock_output_port,false) || !video->EnablePort(omx_aud_rend,omx_rend_clock_port,false)
765 Log::getInstance()->log("Audio", Log::DEBUG, "Enable Ports OMX clock rend failed");
766 video->UnlockClock();
767 DeAllocateCodecsOMX();
771 if (!video->ChangeComponentState(omx_aud_rend,OMX_StateIdle)) {
772 Log::getInstance()->log("Audio", Log::DEBUG, "aud_rend idle ChangeComponentState");
773 video->UnlockClock();
774 DeAllocateCodecsOMX();
781 if ( !video->CommandFinished(omx_aud_rend,OMX_CommandPortEnable,omx_rend_clock_port)) {
782 video->UnlockClock();
783 DeAllocateCodecsOMX();
787 if ( !video->CommandFinished(omx_clock,OMX_CommandPortEnable,omx_clock_output_port)) {
788 video->UnlockClock();
789 DeAllocateCodecsOMX();
795 if (!ChangeAudioPortConfig()){
796 Log::getInstance()->log("Audio", Log::NOTICE, "Change AudioPortConfig failed");
797 video->UnlockClock();
798 DeAllocateCodecsOMX();
802 /* if (!video->ChangeComponentState(omx_aud_dec,OMX_StateIdle)) {
803 Log::getInstance()->log("Audio", Log::DEBUG, "aud_dec ChangeComponentState");
804 DeAllocateCodecsOMX();
810 if (!PrepareInputBufsOMX()) {
811 video->UnlockClock();
812 DeAllocateCodecsOMX();
818 /* error=OMX_SetupTunnel(omx_aud_dec,omx_codec_output_port,omx_aud_rend,omx_rend_input_port);
819 if (error!=OMX_ErrorNone){
820 Log::getInstance()->log("Audio", Log::DEBUG, "OMX_Setup tunnel dec to render failed %x", error);
821 video->UnlockClock();
822 DeAllocateCodecsOMX();
828 /* if (!video->EnablePort(omx_aud_dec,omx_codec_output_port,false) || !video->EnablePort(omx_aud_rend,omx_rend_input_port,false)
830 Log::getInstance()->log("Audio", Log::DEBUG, "Enable Ports OMX codec rend failed");
831 video->UnlockClock();
832 DeAllocateCodecsOMX();
836 /* if ( !video->CommandFinished(omx_aud_dec,OMX_CommandPortEnable,omx_codec_output_port)
837 || !video->CommandFinished(omx_aud_rend,OMX_CommandPortEnable,omx_rend_input_port)) {
838 video->UnlockClock();
839 DeAllocateCodecsOMX();
843 if (!video->ChangeComponentState(omx_aud_rend,OMX_StateExecuting)) {
844 Log::getInstance()->log("Audio", Log::DEBUG, "omx_aud_rend ChangeComponentState Execute");
845 video->UnlockClock();
846 DeAllocateCodecsOMX();
851 video->UnlockClock();
856 if (!video->setClockExecutingandRunning()) return 0;
858 Log::getInstance()->log("Audio", Log::NOTICE, "Allocate Codecs OMX finished");
866 int AudioOMX::PrepareInputBufsOMX() //needs to be called with locvke omx clock mutex
868 VideoOMX *video=(VideoOMX*)Video::getInstance();
870 OMX_PARAM_PORTDEFINITIONTYPE port_def_type;
871 memset(&port_def_type,0,sizeof(port_def_type));
872 port_def_type.nSize=sizeof(port_def_type);
873 port_def_type.nVersion.nVersion=OMX_VERSION;
874 port_def_type.nPortIndex=omx_rend_input_port;//omx_codec_input_port;
876 error=OMX_GetParameter(omx_aud_rend/*dec*/,OMX_IndexParamPortDefinition, &port_def_type);
878 if (error!=OMX_ErrorNone){
879 Log::getInstance()->log("Audio", Log::DEBUG, "Get OMX OMX_IndexParamPortDefinition failed %x", error);
883 port_def_type.nBufferCountActual=2;
884 port_def_type.nBufferSize=max(port_def_type.nBufferSize,50000); // for transcoder important
886 error=OMX_SetParameter(omx_aud_rend/*dec*/,OMX_IndexParamPortDefinition, &port_def_type);
888 if (error!=OMX_ErrorNone){
889 Log::getInstance()->log("Audio", Log::DEBUG, "Set OMX OMX_IndexParamPortDefinition failed %x", error);
893 error=OMX_SendCommand(omx_aud_rend/*dec*/,OMX_CommandPortEnable,omx_rend_input_port/*codec*/,0);
894 if (error!=OMX_ErrorNone){
895 Log::getInstance()->log("Audio", Log::DEBUG, "Prepare Input bufs Send Command to enable port %x", error);
899 input_bufs_omx_mutex.Lock();
900 for (unsigned int i=0; i< port_def_type.nBufferCountActual;i++) {
901 OMX_BUFFERHEADERTYPE *buf_head=NULL;
902 error=OMX_AllocateBuffer(omx_aud_rend/*dec*/,&buf_head,omx_rend_input_port/*codec*/,NULL,port_def_type.nBufferSize);
903 if (error!=OMX_ErrorNone){
904 Log::getInstance()->log("Audio", Log::DEBUG, "Use OMX_AllocateBuffer failed %x", error);
905 input_bufs_omx_mutex.Unlock();
908 input_bufs_omx_all.push_back(buf_head);
909 input_bufs_omx_free.push_back(buf_head);
911 omx_first_frame=true;
914 cur_input_buf_omx=NULL;
915 input_bufs_omx_mutex.Unlock();
917 if (!video->CommandFinished(omx_aud_rend/*dec*/,OMX_CommandPortEnable,omx_rend_input_port /*codec*/)) {
924 int AudioOMX::DestroyInputBufsOMX() //call with clock mutex locked
928 cur_input_buf_omx=NULL;
929 input_bufs_omx_mutex.Lock();
930 for (int i=0; i< input_bufs_omx_all.size();i++) {
931 error=OMX_FreeBuffer(omx_aud_rend/*dec*/,omx_rend_input_port/*codec*/,input_bufs_omx_all[i]);
932 if (error!=OMX_ErrorNone){
933 Log::getInstance()->log("Audio", Log::DEBUG, "Use OMX_FreeBuffer failed %x", error);
934 input_bufs_omx_mutex.Unlock();
939 input_bufs_omx_all.clear();
940 input_bufs_omx_free.clear();
941 input_bufs_omx_mutex.Unlock();
946 int AudioOMX::DeAllocateCodecsOMX()
950 VideoOMX *video=(VideoOMX*)Video::getInstance();
951 Log::getInstance()->log("Audio", Log::DEBUG, "enter deallocatecodecsomx");
955 Log::getInstance()->log("Audio", Log::DEBUG, "deallocatecodecsomx mark 1");
956 if (cur_input_buf_omx) {
957 cur_input_buf_omx->nFlags|=OMX_BUFFERFLAG_EOS;
958 OMX_ERRORTYPE error=OMX_EmptyThisBuffer(omx_aud_rend/*dec*/,cur_input_buf_omx);
959 if (error!=OMX_ErrorNone) {
960 Log::getInstance()->log("Audio", Log::DEBUG, "OMX_EmptyThisBuffer 6 failed %x", error);
963 cur_input_buf_omx=NULL;//write out old data
965 Log::getInstance()->log("Audio", Log::DEBUG, "deallocatecodecsomx mark 2");
967 if (omx_aud_rend/*dec*/) {
968 // first stop the omx elements
969 /* if (!video->ChangeComponentState(omx_aud_dec,OMX_StateIdle)) {
970 Log::getInstance()->log("Audio", Log::DEBUG, "aud_dec ChangeComponentState");
972 Log::getInstance()->log("Audio", Log::DEBUG, "deallocatecodecsomx mark 3");
974 video->UnlockClock();
975 Log::getInstance()->log("Audio", Log::DEBUG, "deallocatecodecsomx mark 4");
977 Log::getInstance()->log("Audio", Log::DEBUG, "deallocatecodecsomx mark 5");
980 if (!video->ChangeComponentState(omx_aud_rend,OMX_StateIdle)) {
981 Log::getInstance()->log("Audio", Log::DEBUG, "aud_rend ChangeComponentState");
984 // TODO proper deinit sequence
985 // first flush all buffers
987 error=OMX_SendCommand(omx_aud_rend,OMX_CommandFlush, omx_rend_input_port, NULL);
988 if (error!=OMX_ErrorNone) {
989 Log::getInstance()->log("Audio", Log::DEBUG, "OMX_Flush rend in failed %x", error);
993 /* error=OMX_SendCommand(omx_aud_dec,OMX_CommandFlush, omx_codec_input_port, NULL);
994 if (error!=OMX_ErrorNone){
995 Log::getInstance()->log("Audio", Log::DEBUG, "OMX_Flush codec out failed %x", error);
1000 /* if (!video->CommandFinished(omx_aud_dec,OMX_CommandFlush,omx_codec_input_port)) {
1001 Log::getInstance()->log("Audio", Log::DEBUG, "flush cmd codec input failed");
1006 error=OMX_SendCommand(omx_clock,OMX_CommandFlush, omx_clock_output_port, NULL);
1007 if (error!=OMX_ErrorNone){
1008 Log::getInstance()->log("Audio", Log::DEBUG, "OMX_Flush clock out failed %x", error);
1012 error=OMX_SendCommand(omx_aud_rend,OMX_CommandFlush, omx_rend_clock_port, NULL);
1013 if (error!=OMX_ErrorNone){
1014 Log::getInstance()->log("Audio", Log::DEBUG, "OMX_Flush rend clock failed %x", error);
1017 Log::getInstance()->log("Audio", Log::DEBUG, "deallocatecodecsomx mark 6");
1019 if (!video->CommandFinished(omx_clock,OMX_CommandFlush,omx_clock_output_port) ||
1020 !video->CommandFinished(omx_aud_rend,OMX_CommandFlush,omx_rend_clock_port)) {
1021 Log::getInstance()->log("Audio", Log::DEBUG, "flush cmd clock shed failed");
1024 DestroyInputBufsOMX(); //We have to make sure that no buffers are in use
1025 Log::getInstance()->log("Audio", Log::DEBUG, "deallocatecodecsomx mark 6a");
1026 DeinitDecoderLibAV();
1027 Log::getInstance()->log("Audio", Log::DEBUG, "deallocatecodecsomx mark 7");
1030 if (!video->DisablePort(omx_aud_rend,omx_rend_input_port,true)) {
1031 Log::getInstance()->log("Audio", Log::DEBUG, "Disable Tunnel Port failed 1");
1034 /* if (!video->DisablePort(omx_aud_dec,omx_codec_output_port,true)) {
1035 Log::getInstance()->log("Audio", Log::DEBUG, "Disable Tunnel Port failed 6");
1038 if (!video->DisablePort(omx_aud_dec,omx_codec_input_port,true)) {
1039 Log::getInstance()->log("Audio", Log::DEBUG, "Disable Tunnel Port failed 7");
1043 if (!video->DisablePort(omx_aud_rend,omx_rend_clock_port,true)) {
1044 Log::getInstance()->log("Audio", Log::DEBUG, "Disable Tunnel Port failed 4");
1047 if (!video->DisablePort(omx_clock,omx_clock_output_port,true)) {
1048 Log::getInstance()->log("Audio", Log::DEBUG, "Disable Tunnel Port failed 5");
1053 /* error=OMX_SetupTunnel(omx_aud_dec,omx_codec_output_port,NULL,NULL);
1054 if (error!=OMX_ErrorNone) {
1055 Log::getInstance()->log("Audio", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
1061 error=OMX_SetupTunnel(omx_aud_rend,omx_rend_input_port,NULL,NULL);
1062 if (error!=OMX_ErrorNone) {
1063 Log::getInstance()->log("Audio", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
1067 error=OMX_SetupTunnel(omx_clock,omx_clock_output_port,NULL,NULL);
1068 if (error!=OMX_ErrorNone) {
1069 Log::getInstance()->log("Audio", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
1073 error=OMX_SetupTunnel(omx_aud_rend,omx_rend_clock_port,NULL,NULL);
1074 if (error!=OMX_ErrorNone) {
1075 Log::getInstance()->log("Audio", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
1078 Log::getInstance()->log("Audio", Log::DEBUG, "deallocatecodecsomx mark 8");
1081 //error=OMX_FreeHandle(omx_aud_dec);
1082 error=OMX_FreeHandle(omx_aud_rend);
1083 video->UnlockClock();
1084 video->destroyClock();
1085 omx_aud_rend/*dec*/=NULL;
1086 if (error!=OMX_ErrorNone) {
1087 Log::getInstance()->log("Audio", Log::DEBUG, "FreeHandle failed %d", error);
1091 video->UnlockClock();
1092 DeinitDecoderLibAV();
1094 Log::getInstance()->log("Audio", Log::DEBUG, "leave deallocate codecs OMX");
1101 int AudioOMX::stop()
1103 if (!initted) return 0;
1105 Log::getInstance()->log("Audio", Log::DEBUG, "Audio stop called");
1106 DeAllocateCodecsOMX();
1107 //if (ioctl(fdAudio, AV_SET_AUD_RESET, 0x11) != 0) return 0;
1111 int AudioOMX::mute()
1113 if (!initted) return 0;
1115 // if (ioctl(fdAudio, AV_SET_AUD_MUTE, 1) != 0) return 0;
1116 Log::getInstance()->log("Audio", Log::DEBUG, "MUTE MUTE MUTE");
1122 int AudioOMX::unMute()
1124 if (!initted) return 0;
1126 // if (ioctl(fdAudio, AV_SET_AUD_MUTE, 0) != 0) return 0;
1127 Log::getInstance()->log("Audio", Log::DEBUG, "MUTE OFF OFF OFF");
1133 int AudioOMX::pause() {
1138 VideoOMX *vw = (VideoOMX*) Video::getInstance();
1140 OMX_ERRORTYPE error;
1141 error = OMX_SendCommand(omx_aud_rend, OMX_CommandFlush,
1142 omx_rend_input_port, NULL);
1143 if (error != OMX_ErrorNone) {
1144 Log::getInstance()->log("Audio", Log::DEBUG,
1145 "OMX_Flush rend in failed %x", error);
1154 int AudioOMX::unPause()
1156 if (!initted) return 0;
1158 paused=false; // may be also change omx clock
1159 VideoOMX *vw = (VideoOMX*) Video::getInstance();
1165 int AudioOMX::reset()
1167 if (!initted) return 0;
1169 Log::getInstance()->log("Audio", Log::DEBUG, "reset called");
1170 DeAllocateCodecsOMX();
1172 // if (ioctl(fdAudio, AV_SET_AUD_RESET, 0x11) != 0) return 0;
1173 // Log::getInstance()->log("Audio", Log::DEBUG, "reset back");
1174 // if (ioctl(fdAudio, AV_SET_AUD_PLAY, 0) != 0) return 0;
1180 int AudioOMX::setVolume(int tvolume)
1182 // parameter: 0 for silence, 20 for full
1183 if ((tvolume < 0) || (tvolume > 20)) return 0;
1185 // volume = 2 * (20 - volume);
1186 // Right, that one was rubbish... 0-10 were almost
1187 // inaudible, 11-20 did what should have been done
1188 // over the whole 0-20 range
1190 tvolume = 20 - tvolume;
1192 audio_volume Avolume;
1193 Avolume.frontleft = tvolume + Aoffset.frontleft;
1194 Avolume.frontright = tvolume + Aoffset.frontright;
1195 Avolume.rearleft = tvolume + Aoffset.rearleft;
1196 Avolume.rearright = tvolume + Aoffset.rearright;
1197 Avolume.center = tvolume + Aoffset.center;
1198 Avolume.lfe = tvolume + Aoffset.lfe;
1200 // if (ioctl(fdAudio, AV_SET_AUD_VOLUME, &Avolume) != 0) return 0;
1202 // unsigned long vol = (tvolume << 24) | (tvolume << 16);
1204 // Log::getInstance()->log("Audio", Log::DEBUG, "%lx", vol);
1205 // Log::getInstance()->log("Audio", Log::DEBUG, "%i", tvolume);
1207 // if (ioctl(fdAudio, AV_SET_AUD_VOLUME, &vol) != 0) return 0;
1212 int AudioOMX::test()
1215 // return ioctl(fdAudio, AV_SET_AUD_STC, &stc);
1217 /* aud_sync_parms_t a;
1221 // int b = ioctl(fdAudio, AV_SET_AUD_DISABLE_SYNC, &a);
1224 /*OK*/ //printf("Audio sync disable = %i\n", b);
1232 void AudioOMX::PrepareMediaSample(const MediaPacketList& mplist,UINT samplepos)
1234 packet = mplist.front();
1237 UINT AudioOMX::DeliverMediaSample(UCHAR* buffer, UINT* samplepos) {
1238 DeliverMediaPacket(packet, buffer, samplepos);
1239 if (*samplepos == packet.length) {
1247 long long AudioOMX::correctAudioLatency(long long pts,int addsamples,int srate) {
1249 VideoOMX *video = (VideoOMX*) Video::getInstance();
1251 OMX_PARAM_U32TYPE audio_lat;
1252 OMX_ERRORTYPE error;
1253 memset(&audio_lat, 0, sizeof(audio_lat));
1254 audio_lat.nSize = sizeof(audio_lat);
1255 audio_lat.nVersion.nVersion = OMX_VERSION;
1256 audio_lat.nPortIndex = omx_rend_input_port;
1258 error = OMX_GetConfig(omx_aud_rend, OMX_IndexConfigAudioRenderingLatency,
1260 video->UnlockClock();
1261 if (error != OMX_ErrorNone) {
1262 Log::getInstance()->log("Audio", Log::DEBUG,
1263 "Init OMX_IndexConfigAudioRenderingLatencyfailed %x %d", error,
1264 omx_rend_input_port);
1265 return pts; // no correction in case of error
1267 /*Log::getInstance()->log("Audio", Log::DEBUG, "Current audio latency %d",
1270 long long workpts=0;
1271 workpts+=addsamples;
1272 workpts-=audio_lat.nU32;
1273 workpts*=10LL*1000LL*1000LL;
1274 workpts=workpts/((long long)srate); //one second /samplerate
1282 UINT AudioOMX::DeliverMediaPacket(MediaPacket packet, const UCHAR* buffer,
1284 /*First Check, if we have an audio sample*/
1285 VideoOMX *vw = (VideoOMX*) Video::getInstance();
1287 OMX_ERRORTYPE error;
1288 Log *logger=Log::getInstance();
1289 if (vw->InIframemode()) {
1292 return 0; //Not in iframe mode!
1295 if (!omx_running) return 0; // if we are not runnig do not do this
1296 if (paused) return 0; //Block if we pause
1298 UINT headerstrip = 0;
1299 if (packet.disconti) {
1300 firstsynched = false;
1301 if (cur_input_buf_omx) {
1302 OMX_ERRORTYPE error = OMX_EmptyThisBuffer(omx_aud_rend/*dec*/,
1304 if (error != OMX_ErrorNone) {
1305 Log::getInstance()->log("Audio", Log::DEBUG,
1306 "OMX_EmptyThisBuffer 1 failed %x", error);
1308 cur_input_buf_omx = NULL;
1312 if (packet.type != lastAType) {//Format Change //Push data out !
1313 firstsynched = false;
1315 lastAType = packet.type;
1317 if (cur_input_buf_omx) {
1318 OMX_ERRORTYPE error = OMX_EmptyThisBuffer(omx_aud_rend/*dec*/,
1320 if (error != OMX_ErrorNone) {
1321 Log::getInstance()->log("Audio", Log::DEBUG,
1322 "OMX_EmptyThisBuffer 2 failed %x", error);
1324 cur_input_buf_omx = NULL;
1326 if (!ChangeAudioPortConfig()) {
1327 Log::getInstance()->log("Audio", Log::DEBUG,
1328 "Changing audio port config failed", error);
1333 /*Inspect PES-Header */
1334 if (*samplepos == 0 && packet.type != MPTYPE_MPEG_AUDIO_LAYER3) {//stripheader
1335 headerstrip = buffer[packet.pos_buffer + 8] + 9;
1336 if (packet.type == MPTYPE_AC3)
1337 headerstrip += 4; //skip ac3 bytes
1338 *samplepos += headerstrip;
1339 if (packet.synched) {
1340 if (cur_input_buf_omx) {
1341 cur_input_buf_omx->nFlags |= OMX_BUFFERFLAG_ENDOFFRAME;
1342 OMX_ERRORTYPE error = OMX_EmptyThisBuffer(omx_aud_rend/*dec*/,
1344 if (error != OMX_ErrorNone) {
1345 Log::getInstance()->log("Audio", Log::DEBUG,
1346 "OMX_EmptyThisBuffer 3 failed %x", error);
1348 //FrameWaitforDisplay(lastreftimeOMX);
1349 vw->AdjustAudioPTS(correctAudioLatency(lastreftimeOMX,cur_input_buf_omx->nFilledLen/(2*2),48000));
1351 cur_input_buf_omx = NULL;//write out old data
1353 firstsynched = true;
1355 if (!firstsynched) {//
1356 *samplepos = packet.length;//if we have not processed at least one
1357 return packet.length;//synched packet ignore it!
1361 if (!cur_input_buf_omx) {
1362 input_bufs_omx_mutex.Lock();
1363 if (input_bufs_omx_free.size()==0) {
1364 input_bufs_omx_mutex.Unlock();
1365 //Log::getInstance()->log("Audio", Log::DEBUG, "Deliver MediaPacket no free sample");
1366 return 0; // we do not have a free media sample
1369 cur_input_buf_omx=input_bufs_omx_free.front();
1370 cur_input_buf_omx->nFilledLen=0;
1371 cur_input_buf_omx->nOffset=0;
1372 cur_input_buf_omx->nTimeStamp=0;
1373 input_bufs_omx_free.pop_front();
1374 input_bufs_omx_mutex.Unlock();
1378 if (cur_input_buf_omx->nFilledLen == 0) {//will only be changed on first packet
1379 if (packet.synched) {
1380 //Log::getInstance()->log("Audio", Log::DEBUG,
1381 // "packet synched marker");
1383 //lastreftimePTS=packet.pts;
1384 if (omx_first_frame) { // TODO time
1385 cur_input_buf_omx->nFlags = OMX_BUFFERFLAG_STARTTIME;
1386 Log::getInstance()->log("Audio", Log::DEBUG, "Starttime");
1387 omx_first_frame = false;
1389 cur_input_buf_omx->nFlags = 0;
1390 cur_input_buf_omx->nFlags|=OMX_BUFFERFLAG_TIME_UNKNOWN;
1392 lastreftimeOMX = packet.presentation_time;
1393 Log::getInstance()->log("Audio", Log::DEBUG,
1394 "Time code %lld pts %lld dts %lld", lastreftimeOMX, packet.pts,packet.dts);
1395 lastreftimePTS = packet.pts;
1396 cur_input_buf_omx->nTimeStamp =0;// lastreftimeOMX; // the clock component is faulty;
1398 // Log::getInstance()->log("Audio", Log::DEBUG,
1399 // "packet NOT synched marker");
1400 cur_input_buf_omx->nFlags = OMX_BUFFERFLAG_TIME_UNKNOWN;
1401 cur_input_buf_omx->nTimeStamp = 0;
1404 if (packet.disconti || achange) {
1405 cur_input_buf_omx->nFlags |= OMX_BUFFERFLAG_DISCONTINUITY;
1406 //mp23codec_context_libav->frame_size=-1;
1407 //ac3codec_context_libav->frame_size=-1;
1412 unsigned int haveToCopy=packet.length-*samplepos;
1421 AVCodecContext *current_context;
1422 switch (packet.type) {
1423 case MPTYPE_MPEG_AUDIO:
1424 case MPTYPE_MPEG_AUDIO_LAYER3: {
1425 current_context = mp23codec_context_libav;
1426 if (current_context->frame_size<0) framesize=1152; //Maximum framesize
1427 else framesize=current_context->frame_size;
1430 case MPTYPE_AC3_PRE13: {
1431 current_context = ac3codec_context_libav;
1435 incoming_paket_libav.data =(uint8_t*) buffer+packet.pos_buffer+*samplepos;
1436 incoming_paket_libav.size = haveToCopy;
1438 while (haveToCopy> 0 && errcount<2) {
1440 //Log::getInstance()->log("Audio", Log::DEBUG,"libav in %d %d",framesize,current_context->frame_size);
1441 //Log::getInstance()->log("Audio", Log::DEBUG, "libav in %d %d",
1442 // framesize, current_context->frame_size);
1445 pthread_testcancel();
1446 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldcancelstate);
1447 pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldcanceltype);
1449 if (!omx_running || !mp23codec_context_libav
1450 || !ac3codec_context_libav) {
1451 libav_mutex.Unlock();
1454 libav_mutex.Unlock();
1455 // Log::getInstance()->log("Audio", Log::DEBUG,"libav out");
1456 len = avcodec_decode_audio4(current_context, decode_frame_libav,
1457 &gotta, &incoming_paket_libav);
1458 //Log::getInstance()->log("Audio", Log::DEBUG, "libav out1");
1459 pthread_setcancelstate(oldcancelstate, NULL);
1460 pthread_setcanceltype(oldcanceltype, NULL);
1461 pthread_testcancel();
1463 //Log::getInstance()->log("Audio", Log::DEBUG, "libav out2");
1465 libav_mutex.Unlock();
1470 incoming_paket_libav.data += len;
1474 if (current_context->frame_size>0) framesize=min(current_context->frame_size,haveToCopy);
1475 else framesize=haveToCopy;
1478 framesize=haveToCopy;
1481 incoming_paket_libav.size =framesize;
1483 //Log::getInstance()->log("Audio", Log::DEBUG,
1485 int dsize = av_samples_get_buffer_size(NULL,
1486 current_context->channels, decode_frame_libav->nb_samples,
1487 current_context->sample_fmt, 1);
1488 if ((cur_input_buf_omx->nFilledLen + dsize)
1489 > cur_input_buf_omx->nAllocLen ) {
1490 // I doubt that this will ever happen
1491 Log::getInstance()->log("Audio", Log::DEBUG,
1492 "P 2 Time code %lld pts %lld", lastreftimeOMX, packet.pts);
1493 OMX_ERRORTYPE error = OMX_EmptyThisBuffer(omx_aud_rend/*dec*/,
1495 if (error != OMX_ErrorNone) {
1496 Log::getInstance()->log("Audio", Log::DEBUG,
1497 "OMX_EmptyThisBuffer 4 failed %x", error);
1499 cur_input_buf_omx = NULL;
1501 if (!cur_input_buf_omx) {
1503 while (count < 10 && omx_running) {
1505 input_bufs_omx_mutex.Lock();
1506 if (input_bufs_omx_free.size() == 0) {
1507 input_bufs_omx_mutex.Unlock();
1508 Log::getInstance()->log("Audio", Log::DEBUG,
1509 "Deliver MediaPacket no free sample");
1511 if (!omx_running) return *samplepos;
1514 cur_input_buf_omx = input_bufs_omx_free.front();
1515 cur_input_buf_omx->nFilledLen = 0;
1516 cur_input_buf_omx->nOffset = 0;
1517 cur_input_buf_omx->nTimeStamp = 0;
1518 input_bufs_omx_free.pop_front();
1519 input_bufs_omx_mutex.Unlock();
1522 if (!cur_input_buf_omx) return *samplepos;
1527 //Log::getInstance()->log("Audio", Log::DEBUG,"memcpy in %d %d %d" ,dsize,current_context->sample_rate,cur_input_buf_omx->nFilledLen);
1528 memcpy(cur_input_buf_omx->pBuffer + cur_input_buf_omx->nFilledLen,
1529 decode_frame_libav->data[0], dsize);
1530 //Log::getInstance()->log("Audio", Log::DEBUG,"memcpy out");
1531 cur_input_buf_omx->nFilledLen += dsize;
1533 //Log::getInstance()->log("Audio", Log::DEBUG,"Incomplete mpeg frames in pes packet %d",incoming_paket_libav.size);
1540 if (cur_input_buf_omx->nFilledLen) {
1541 Log::getInstance()->log("Audio", Log::DEBUG,
1542 "P 3 Time code %lld pts %lld", lastreftimeOMX, packet.pts);
1543 error = OMX_EmptyThisBuffer(omx_aud_rend/*dec*/, cur_input_buf_omx);
1544 if (error != OMX_ErrorNone) {
1545 Log::getInstance()->log("Audio", Log::DEBUG,
1546 "OMX_EmptyThisBuffer 5 failed %x", error);
1548 if (packet.synched) vw->AdjustAudioPTS(correctAudioLatency(lastreftimeOMX,cur_input_buf_omx->nFilledLen/(2*2),48000));
1549 cur_input_buf_omx = NULL;
1554 *samplepos=packet.length;
1555 return packet.length;
1561 long long AudioOMX::SetStartOffset(long long curreftime, bool *rsync){
1562 VideoOMX *vw=(VideoOMX*)Video::getInstance();
1563 return vw->SetStartAudioOffset(curreftime,rsync);
1566 void AudioOMX::ResetTimeOffsets() {
1567 VideoOMX *vw=(VideoOMX*)Video::getInstance();
1568 vw->ResetTimeOffsets();