147e37c4428509524ee576920a98381f3e4872493Nick Pelly/*--------------------------------------------------------------------------
2826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan MalchevCopyright (c) 2010-2012, Code Aurora Forum. All rights reserved.
347e37c4428509524ee576920a98381f3e4872493Nick Pelly
447e37c4428509524ee576920a98381f3e4872493Nick PellyRedistribution and use in source and binary forms, with or without
547e37c4428509524ee576920a98381f3e4872493Nick Pellymodification, are permitted provided that the following conditions are met:
647e37c4428509524ee576920a98381f3e4872493Nick Pelly    * Redistributions of source code must retain the above copyright
747e37c4428509524ee576920a98381f3e4872493Nick Pelly      notice, this list of conditions and the following disclaimer.
847e37c4428509524ee576920a98381f3e4872493Nick Pelly    * Redistributions in binary form must reproduce the above copyright
947e37c4428509524ee576920a98381f3e4872493Nick Pelly      notice, this list of conditions and the following disclaimer in the
1047e37c4428509524ee576920a98381f3e4872493Nick Pelly      documentation and/or other materials provided with the distribution.
1147e37c4428509524ee576920a98381f3e4872493Nick Pelly    * Neither the name of Code Aurora nor
1247e37c4428509524ee576920a98381f3e4872493Nick Pelly      the names of its contributors may be used to endorse or promote
1347e37c4428509524ee576920a98381f3e4872493Nick Pelly      products derived from this software without specific prior written
1447e37c4428509524ee576920a98381f3e4872493Nick Pelly      permission.
1547e37c4428509524ee576920a98381f3e4872493Nick Pelly
1647e37c4428509524ee576920a98381f3e4872493Nick PellyTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1747e37c4428509524ee576920a98381f3e4872493Nick PellyAND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1847e37c4428509524ee576920a98381f3e4872493Nick PellyIMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
1947e37c4428509524ee576920a98381f3e4872493Nick PellyNON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
2047e37c4428509524ee576920a98381f3e4872493Nick PellyCONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
2147e37c4428509524ee576920a98381f3e4872493Nick PellyEXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
2247e37c4428509524ee576920a98381f3e4872493Nick PellyPROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
2347e37c4428509524ee576920a98381f3e4872493Nick PellyOR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
2447e37c4428509524ee576920a98381f3e4872493Nick PellyWHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
2547e37c4428509524ee576920a98381f3e4872493Nick PellyOTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
2647e37c4428509524ee576920a98381f3e4872493Nick PellyADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2747e37c4428509524ee576920a98381f3e4872493Nick Pelly--------------------------------------------------------------------------*/
2847e37c4428509524ee576920a98381f3e4872493Nick Pelly/*============================================================================
2947e37c4428509524ee576920a98381f3e4872493Nick Pelly                            O p e n M A X   w r a p p e r s
3047e37c4428509524ee576920a98381f3e4872493Nick Pelly                             O p e n  M A X   C o r e
3147e37c4428509524ee576920a98381f3e4872493Nick Pelly
3247e37c4428509524ee576920a98381f3e4872493Nick Pelly*//** @file omx_video_base.cpp
3347e37c4428509524ee576920a98381f3e4872493Nick Pelly  This module contains the implementation of the OpenMAX core & component.
3447e37c4428509524ee576920a98381f3e4872493Nick Pelly
3547e37c4428509524ee576920a98381f3e4872493Nick Pelly*//*========================================================================*/
3647e37c4428509524ee576920a98381f3e4872493Nick Pelly
3747e37c4428509524ee576920a98381f3e4872493Nick Pelly//////////////////////////////////////////////////////////////////////////////
3847e37c4428509524ee576920a98381f3e4872493Nick Pelly//                             Include Files
3947e37c4428509524ee576920a98381f3e4872493Nick Pelly//////////////////////////////////////////////////////////////////////////////
4047e37c4428509524ee576920a98381f3e4872493Nick Pelly
4147e37c4428509524ee576920a98381f3e4872493Nick Pelly#include <string.h>
4247e37c4428509524ee576920a98381f3e4872493Nick Pelly#include "omx_video_base.h"
4347e37c4428509524ee576920a98381f3e4872493Nick Pelly#include <stdlib.h>
4447e37c4428509524ee576920a98381f3e4872493Nick Pelly#include <errno.h>
4547e37c4428509524ee576920a98381f3e4872493Nick Pelly#include <fcntl.h>
4647e37c4428509524ee576920a98381f3e4872493Nick Pelly#include <unistd.h>
47826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#include <sys/prctl.h>
48826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#ifdef _ANDROID_ICS_
49826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#include <media/hardware/HardwareAPI.h>
50826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#include <gralloc_priv.h>
51826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#endif
52826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#ifndef _ANDROID_
53826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#include <glib.h>
54826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#define strlcpy g_strlcpy
55826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#endif
5647e37c4428509524ee576920a98381f3e4872493Nick Pelly#define H264_SUPPORTED_WIDTH (480)
5747e37c4428509524ee576920a98381f3e4872493Nick Pelly#define H264_SUPPORTED_HEIGHT (368)
5847e37c4428509524ee576920a98381f3e4872493Nick Pelly
5947e37c4428509524ee576920a98381f3e4872493Nick Pelly#define MPEG4_SUPPORTED_WIDTH (480)
6047e37c4428509524ee576920a98381f3e4872493Nick Pelly#define MPEG4_SUPPORTED_HEIGHT (368)
6147e37c4428509524ee576920a98381f3e4872493Nick Pelly
6247e37c4428509524ee576920a98381f3e4872493Nick Pelly#define VC1_SP_MP_START_CODE        0xC5000000
6347e37c4428509524ee576920a98381f3e4872493Nick Pelly#define VC1_SP_MP_START_CODE_MASK   0xFF000000
6447e37c4428509524ee576920a98381f3e4872493Nick Pelly#define VC1_AP_START_CODE           0x00000100
6547e37c4428509524ee576920a98381f3e4872493Nick Pelly#define VC1_AP_START_CODE_MASK      0xFFFFFF00
6647e37c4428509524ee576920a98381f3e4872493Nick Pelly#define VC1_STRUCT_C_PROFILE_MASK   0xF0
6747e37c4428509524ee576920a98381f3e4872493Nick Pelly#define VC1_STRUCT_B_LEVEL_MASK     0xE0000000
6847e37c4428509524ee576920a98381f3e4872493Nick Pelly#define VC1_SIMPLE_PROFILE          0
6947e37c4428509524ee576920a98381f3e4872493Nick Pelly#define VC1_MAIN_PROFILE            1
7047e37c4428509524ee576920a98381f3e4872493Nick Pelly#define VC1_ADVANCE_PROFILE         3
7147e37c4428509524ee576920a98381f3e4872493Nick Pelly#define VC1_SIMPLE_PROFILE_LOW_LEVEL  0
7247e37c4428509524ee576920a98381f3e4872493Nick Pelly#define VC1_SIMPLE_PROFILE_MED_LEVEL  2
7347e37c4428509524ee576920a98381f3e4872493Nick Pelly#define VC1_STRUCT_C_LEN            4
7447e37c4428509524ee576920a98381f3e4872493Nick Pelly#define VC1_STRUCT_C_POS            8
7547e37c4428509524ee576920a98381f3e4872493Nick Pelly#define VC1_STRUCT_A_POS            12
7647e37c4428509524ee576920a98381f3e4872493Nick Pelly#define VC1_STRUCT_B_POS            24
7747e37c4428509524ee576920a98381f3e4872493Nick Pelly#define VC1_SEQ_LAYER_SIZE          36
7847e37c4428509524ee576920a98381f3e4872493Nick Pelly
79525cc9b815b0cb86e4fc02be0bfa5f1e363804f6Praveen Chavan#define IS_NOT_ALIGNED( num, to) (num & (to-1))
80525cc9b815b0cb86e4fc02be0bfa5f1e363804f6Praveen Chavan#define ALIGN( num, to ) (((num) + (to-1)) & (~(to-1)))
81525cc9b815b0cb86e4fc02be0bfa5f1e363804f6Praveen Chavan#define SZ_2K (2048)
82525cc9b815b0cb86e4fc02be0bfa5f1e363804f6Praveen Chavan
8347e37c4428509524ee576920a98381f3e4872493Nick Pellytypedef struct OMXComponentCapabilityFlagsType
8447e37c4428509524ee576920a98381f3e4872493Nick Pelly{
8547e37c4428509524ee576920a98381f3e4872493Nick Pelly    ////////////////// OMX COMPONENT CAPABILITY RELATED MEMBERS
8647e37c4428509524ee576920a98381f3e4872493Nick Pelly    OMX_BOOL iIsOMXComponentMultiThreaded;
8747e37c4428509524ee576920a98381f3e4872493Nick Pelly    OMX_BOOL iOMXComponentSupportsExternalOutputBufferAlloc;
8847e37c4428509524ee576920a98381f3e4872493Nick Pelly    OMX_BOOL iOMXComponentSupportsExternalInputBufferAlloc;
8947e37c4428509524ee576920a98381f3e4872493Nick Pelly    OMX_BOOL iOMXComponentSupportsMovableInputBuffers;
9047e37c4428509524ee576920a98381f3e4872493Nick Pelly    OMX_BOOL iOMXComponentSupportsPartialFrames;
9147e37c4428509524ee576920a98381f3e4872493Nick Pelly    OMX_BOOL iOMXComponentUsesNALStartCodes;
9247e37c4428509524ee576920a98381f3e4872493Nick Pelly    OMX_BOOL iOMXComponentCanHandleIncompleteFrames;
9347e37c4428509524ee576920a98381f3e4872493Nick Pelly    OMX_BOOL iOMXComponentUsesFullAVCFrames;
9447e37c4428509524ee576920a98381f3e4872493Nick Pelly
9547e37c4428509524ee576920a98381f3e4872493Nick Pelly} OMXComponentCapabilityFlagsType;
9647e37c4428509524ee576920a98381f3e4872493Nick Pelly#define OMX_COMPONENT_CAPABILITY_TYPE_INDEX 0xFF7A347
97826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#ifdef OUTPUT_BUFFER_LOG
98826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchevextern FILE *outputBufferFile1;
99826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#endif
100826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev
10147e37c4428509524ee576920a98381f3e4872493Nick Pellyvoid* message_thread(void *input)
10247e37c4428509524ee576920a98381f3e4872493Nick Pelly{
10347e37c4428509524ee576920a98381f3e4872493Nick Pelly  omx_video* omx = reinterpret_cast<omx_video*>(input);
10447e37c4428509524ee576920a98381f3e4872493Nick Pelly  unsigned char id;
10547e37c4428509524ee576920a98381f3e4872493Nick Pelly  int n;
10647e37c4428509524ee576920a98381f3e4872493Nick Pelly
10747e37c4428509524ee576920a98381f3e4872493Nick Pelly  DEBUG_PRINT_LOW("omx_venc: message thread start\n");
108826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  prctl(PR_SET_NAME, (unsigned long)"VideoEncMsgThread", 0, 0, 0);
10947e37c4428509524ee576920a98381f3e4872493Nick Pelly  while(1)
11047e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
11147e37c4428509524ee576920a98381f3e4872493Nick Pelly    n = read(omx->m_pipe_in, &id, 1);
11247e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(0 == n)
11347e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
11447e37c4428509524ee576920a98381f3e4872493Nick Pelly      break;
11547e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
11647e37c4428509524ee576920a98381f3e4872493Nick Pelly
11747e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(1 == n)
11847e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
11947e37c4428509524ee576920a98381f3e4872493Nick Pelly      omx->process_event_cb(omx, id);
12047e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
12147e37c4428509524ee576920a98381f3e4872493Nick Pelly#ifdef QLE_BUILD
12247e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(n < 0) break;
12347e37c4428509524ee576920a98381f3e4872493Nick Pelly#else
12447e37c4428509524ee576920a98381f3e4872493Nick Pelly    if((n < 0) && (errno != EINTR)) break;
12547e37c4428509524ee576920a98381f3e4872493Nick Pelly#endif
12647e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
12747e37c4428509524ee576920a98381f3e4872493Nick Pelly  DEBUG_PRINT_LOW("omx_venc: message thread stop\n");
12847e37c4428509524ee576920a98381f3e4872493Nick Pelly  return 0;
12947e37c4428509524ee576920a98381f3e4872493Nick Pelly}
13047e37c4428509524ee576920a98381f3e4872493Nick Pelly
13147e37c4428509524ee576920a98381f3e4872493Nick Pellyvoid post_message(omx_video *omx, unsigned char id)
13247e37c4428509524ee576920a98381f3e4872493Nick Pelly{
13347e37c4428509524ee576920a98381f3e4872493Nick Pelly  DEBUG_PRINT_LOW("omx_venc: post_message %d\n", id);
13447e37c4428509524ee576920a98381f3e4872493Nick Pelly  write(omx->m_pipe_out, &id, 1);
13547e37c4428509524ee576920a98381f3e4872493Nick Pelly}
13647e37c4428509524ee576920a98381f3e4872493Nick Pelly
13747e37c4428509524ee576920a98381f3e4872493Nick Pelly// omx_cmd_queue destructor
13847e37c4428509524ee576920a98381f3e4872493Nick Pellyomx_video::omx_cmd_queue::~omx_cmd_queue()
13947e37c4428509524ee576920a98381f3e4872493Nick Pelly{
14047e37c4428509524ee576920a98381f3e4872493Nick Pelly  // Nothing to do
14147e37c4428509524ee576920a98381f3e4872493Nick Pelly}
14247e37c4428509524ee576920a98381f3e4872493Nick Pelly
14347e37c4428509524ee576920a98381f3e4872493Nick Pelly// omx cmd queue constructor
14447e37c4428509524ee576920a98381f3e4872493Nick Pellyomx_video::omx_cmd_queue::omx_cmd_queue(): m_read(0),m_write(0),m_size(0)
14547e37c4428509524ee576920a98381f3e4872493Nick Pelly{
14647e37c4428509524ee576920a98381f3e4872493Nick Pelly  memset(m_q,0,sizeof(omx_event)*OMX_CORE_CONTROL_CMDQ_SIZE);
14747e37c4428509524ee576920a98381f3e4872493Nick Pelly}
14847e37c4428509524ee576920a98381f3e4872493Nick Pelly
14947e37c4428509524ee576920a98381f3e4872493Nick Pelly// omx cmd queue insert
15047e37c4428509524ee576920a98381f3e4872493Nick Pellybool omx_video::omx_cmd_queue::insert_entry(unsigned p1, unsigned p2, unsigned id)
15147e37c4428509524ee576920a98381f3e4872493Nick Pelly{
15247e37c4428509524ee576920a98381f3e4872493Nick Pelly  bool ret = true;
15347e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(m_size < OMX_CORE_CONTROL_CMDQ_SIZE)
15447e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
15547e37c4428509524ee576920a98381f3e4872493Nick Pelly    m_q[m_write].id       = id;
15647e37c4428509524ee576920a98381f3e4872493Nick Pelly    m_q[m_write].param1   = p1;
15747e37c4428509524ee576920a98381f3e4872493Nick Pelly    m_q[m_write].param2   = p2;
15847e37c4428509524ee576920a98381f3e4872493Nick Pelly    m_write++;
15947e37c4428509524ee576920a98381f3e4872493Nick Pelly    m_size ++;
16047e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(m_write >= OMX_CORE_CONTROL_CMDQ_SIZE)
16147e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
16247e37c4428509524ee576920a98381f3e4872493Nick Pelly      m_write = 0;
16347e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
16447e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
16547e37c4428509524ee576920a98381f3e4872493Nick Pelly  else
16647e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
16747e37c4428509524ee576920a98381f3e4872493Nick Pelly    ret = false;
16847e37c4428509524ee576920a98381f3e4872493Nick Pelly    DEBUG_PRINT_ERROR("ERROR!!! Command Queue Full\n");
16947e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
17047e37c4428509524ee576920a98381f3e4872493Nick Pelly  return ret;
17147e37c4428509524ee576920a98381f3e4872493Nick Pelly}
17247e37c4428509524ee576920a98381f3e4872493Nick Pelly
17347e37c4428509524ee576920a98381f3e4872493Nick Pelly// omx cmd queue pop
17447e37c4428509524ee576920a98381f3e4872493Nick Pellybool omx_video::omx_cmd_queue::pop_entry(unsigned *p1, unsigned *p2, unsigned *id)
17547e37c4428509524ee576920a98381f3e4872493Nick Pelly{
17647e37c4428509524ee576920a98381f3e4872493Nick Pelly  bool ret = true;
17747e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(m_size > 0)
17847e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
17947e37c4428509524ee576920a98381f3e4872493Nick Pelly    *id = m_q[m_read].id;
18047e37c4428509524ee576920a98381f3e4872493Nick Pelly    *p1 = m_q[m_read].param1;
18147e37c4428509524ee576920a98381f3e4872493Nick Pelly    *p2 = m_q[m_read].param2;
18247e37c4428509524ee576920a98381f3e4872493Nick Pelly    // Move the read pointer ahead
18347e37c4428509524ee576920a98381f3e4872493Nick Pelly    ++m_read;
18447e37c4428509524ee576920a98381f3e4872493Nick Pelly    --m_size;
18547e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(m_read >= OMX_CORE_CONTROL_CMDQ_SIZE)
18647e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
18747e37c4428509524ee576920a98381f3e4872493Nick Pelly      m_read = 0;
18847e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
18947e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
19047e37c4428509524ee576920a98381f3e4872493Nick Pelly  else
19147e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
19247e37c4428509524ee576920a98381f3e4872493Nick Pelly    ret = false;
19347e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
19447e37c4428509524ee576920a98381f3e4872493Nick Pelly  return ret;
19547e37c4428509524ee576920a98381f3e4872493Nick Pelly}
19647e37c4428509524ee576920a98381f3e4872493Nick Pelly
19747e37c4428509524ee576920a98381f3e4872493Nick Pelly// Retrieve the first mesg type in the queue
19847e37c4428509524ee576920a98381f3e4872493Nick Pellyunsigned omx_video::omx_cmd_queue::get_q_msg_type()
19947e37c4428509524ee576920a98381f3e4872493Nick Pelly{
20047e37c4428509524ee576920a98381f3e4872493Nick Pelly  return m_q[m_read].id;
20147e37c4428509524ee576920a98381f3e4872493Nick Pelly}
20247e37c4428509524ee576920a98381f3e4872493Nick Pelly
20347e37c4428509524ee576920a98381f3e4872493Nick Pelly
20447e37c4428509524ee576920a98381f3e4872493Nick Pelly
20547e37c4428509524ee576920a98381f3e4872493Nick Pelly#ifdef _ANDROID_
20647e37c4428509524ee576920a98381f3e4872493Nick PellyVideoHeap::VideoHeap(int fd, size_t size, void* base)
20747e37c4428509524ee576920a98381f3e4872493Nick Pelly{
20847e37c4428509524ee576920a98381f3e4872493Nick Pelly  // dup file descriptor, map once, use pmem
209826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  init(dup(fd), base, size, 0 , MEM_DEVICE);
21047e37c4428509524ee576920a98381f3e4872493Nick Pelly}
21147e37c4428509524ee576920a98381f3e4872493Nick Pelly#endif // _ANDROID_
21247e37c4428509524ee576920a98381f3e4872493Nick Pelly
21347e37c4428509524ee576920a98381f3e4872493Nick Pelly/* ======================================================================
21447e37c4428509524ee576920a98381f3e4872493Nick PellyFUNCTION
21547e37c4428509524ee576920a98381f3e4872493Nick Pelly  omx_venc::omx_venc
21647e37c4428509524ee576920a98381f3e4872493Nick Pelly
21747e37c4428509524ee576920a98381f3e4872493Nick PellyDESCRIPTION
21847e37c4428509524ee576920a98381f3e4872493Nick Pelly  Constructor
21947e37c4428509524ee576920a98381f3e4872493Nick Pelly
22047e37c4428509524ee576920a98381f3e4872493Nick PellyPARAMETERS
22147e37c4428509524ee576920a98381f3e4872493Nick Pelly  None
22247e37c4428509524ee576920a98381f3e4872493Nick Pelly
22347e37c4428509524ee576920a98381f3e4872493Nick PellyRETURN VALUE
22447e37c4428509524ee576920a98381f3e4872493Nick Pelly  None.
22547e37c4428509524ee576920a98381f3e4872493Nick Pelly========================================================================== */
22647e37c4428509524ee576920a98381f3e4872493Nick Pellyomx_video::omx_video(): m_state(OMX_StateInvalid),
22747e37c4428509524ee576920a98381f3e4872493Nick Pelly                        m_app_data(NULL),
22847e37c4428509524ee576920a98381f3e4872493Nick Pelly                        m_inp_mem_ptr(NULL),
22947e37c4428509524ee576920a98381f3e4872493Nick Pelly                        m_out_mem_ptr(NULL),
230826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev                        m_pInput_pmem(NULL),
231826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev                        m_pOutput_pmem(NULL),
232826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#ifdef USE_ION
233826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev                        m_pInput_ion(NULL),
234826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev                        m_pOutput_ion(NULL),
235826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#endif
23647e37c4428509524ee576920a98381f3e4872493Nick Pelly                        pending_input_buffers(0),
23747e37c4428509524ee576920a98381f3e4872493Nick Pelly                        pending_output_buffers(0),
23847e37c4428509524ee576920a98381f3e4872493Nick Pelly                        m_out_bm_count(0),
23947e37c4428509524ee576920a98381f3e4872493Nick Pelly                        m_inp_bm_count(0),
24047e37c4428509524ee576920a98381f3e4872493Nick Pelly                        m_flags(0),
24147e37c4428509524ee576920a98381f3e4872493Nick Pelly                        m_event_port_settings_sent(false),
24247e37c4428509524ee576920a98381f3e4872493Nick Pelly                        output_flush_progress (false),
24347e37c4428509524ee576920a98381f3e4872493Nick Pelly                        input_flush_progress (false),
24447e37c4428509524ee576920a98381f3e4872493Nick Pelly                        input_use_buffer (false),
24547e37c4428509524ee576920a98381f3e4872493Nick Pelly                        output_use_buffer (false),
24647e37c4428509524ee576920a98381f3e4872493Nick Pelly                        m_use_input_pmem(OMX_FALSE),
24747e37c4428509524ee576920a98381f3e4872493Nick Pelly                        m_use_output_pmem(OMX_FALSE),
24847e37c4428509524ee576920a98381f3e4872493Nick Pelly                        m_etb_count(0),
249826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev                        m_fbd_count(0),
2507eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George                        m_error_propogated(false),
2517eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George                        m_input_msg_id(OMX_COMPONENT_GENERATE_ETB),
2527eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George                        psource_frame(NULL),
2537eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George                        pdest_frame(NULL),
2547783f07680c4e868295efbd0cf55a1622a106522Deva Ramasubramanian                        c2d_opened(false),
2557783f07680c4e868295efbd0cf55a1622a106522Deva Ramasubramanian                        secure_session(false)
25647e37c4428509524ee576920a98381f3e4872493Nick Pelly{
25747e37c4428509524ee576920a98381f3e4872493Nick Pelly  DEBUG_PRINT_HIGH("\n omx_video(): Inside Constructor()");
25847e37c4428509524ee576920a98381f3e4872493Nick Pelly  memset(&m_cmp,0,sizeof(m_cmp));
25947e37c4428509524ee576920a98381f3e4872493Nick Pelly  memset(&m_pCallbacks,0,sizeof(m_pCallbacks));
2607783f07680c4e868295efbd0cf55a1622a106522Deva Ramasubramanian  secure_color_format = (int) OMX_COLOR_FormatYUV420SemiPlanar;
26147e37c4428509524ee576920a98381f3e4872493Nick Pelly  pthread_mutex_init(&m_lock, NULL);
26247e37c4428509524ee576920a98381f3e4872493Nick Pelly  sem_init(&m_cmd_lock,0,0);
26347e37c4428509524ee576920a98381f3e4872493Nick Pelly}
26447e37c4428509524ee576920a98381f3e4872493Nick Pelly
26547e37c4428509524ee576920a98381f3e4872493Nick Pelly
26647e37c4428509524ee576920a98381f3e4872493Nick Pelly/* ======================================================================
26747e37c4428509524ee576920a98381f3e4872493Nick PellyFUNCTION
26847e37c4428509524ee576920a98381f3e4872493Nick Pelly  omx_venc::~omx_venc
26947e37c4428509524ee576920a98381f3e4872493Nick Pelly
27047e37c4428509524ee576920a98381f3e4872493Nick PellyDESCRIPTION
27147e37c4428509524ee576920a98381f3e4872493Nick Pelly  Destructor
27247e37c4428509524ee576920a98381f3e4872493Nick Pelly
27347e37c4428509524ee576920a98381f3e4872493Nick PellyPARAMETERS
27447e37c4428509524ee576920a98381f3e4872493Nick Pelly  None
27547e37c4428509524ee576920a98381f3e4872493Nick Pelly
27647e37c4428509524ee576920a98381f3e4872493Nick PellyRETURN VALUE
27747e37c4428509524ee576920a98381f3e4872493Nick Pelly  None.
27847e37c4428509524ee576920a98381f3e4872493Nick Pelly========================================================================== */
27947e37c4428509524ee576920a98381f3e4872493Nick Pellyomx_video::~omx_video()
28047e37c4428509524ee576920a98381f3e4872493Nick Pelly{
28147e37c4428509524ee576920a98381f3e4872493Nick Pelly  DEBUG_PRINT_HIGH("\n ~omx_video(): Inside Destructor()");
28247e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(m_pipe_in) close(m_pipe_in);
28347e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(m_pipe_out) close(m_pipe_out);
28447e37c4428509524ee576920a98381f3e4872493Nick Pelly  DEBUG_PRINT_HIGH("omx_video: Waiting on Msg Thread exit\n");
28547e37c4428509524ee576920a98381f3e4872493Nick Pelly  pthread_join(msg_thread_id,NULL);
28647e37c4428509524ee576920a98381f3e4872493Nick Pelly  DEBUG_PRINT_HIGH("omx_video: Waiting on Async Thread exit\n");
28747e37c4428509524ee576920a98381f3e4872493Nick Pelly  pthread_join(async_thread_id,NULL);
28847e37c4428509524ee576920a98381f3e4872493Nick Pelly  pthread_mutex_destroy(&m_lock);
28947e37c4428509524ee576920a98381f3e4872493Nick Pelly  sem_destroy(&m_cmd_lock);
29047e37c4428509524ee576920a98381f3e4872493Nick Pelly  DEBUG_PRINT_HIGH("\n m_etb_count = %u, m_fbd_count = %u\n", m_etb_count,
29147e37c4428509524ee576920a98381f3e4872493Nick Pelly      m_fbd_count);
29247e37c4428509524ee576920a98381f3e4872493Nick Pelly  DEBUG_PRINT_HIGH("omx_video: Destructor exit\n");
29347e37c4428509524ee576920a98381f3e4872493Nick Pelly  DEBUG_PRINT_HIGH("Exiting 7x30 OMX Video Encoder ...\n");
29447e37c4428509524ee576920a98381f3e4872493Nick Pelly}
29547e37c4428509524ee576920a98381f3e4872493Nick Pelly
29647e37c4428509524ee576920a98381f3e4872493Nick Pelly/* ======================================================================
29747e37c4428509524ee576920a98381f3e4872493Nick PellyFUNCTION
29847e37c4428509524ee576920a98381f3e4872493Nick Pelly  omx_venc::OMXCntrlProcessMsgCb
29947e37c4428509524ee576920a98381f3e4872493Nick Pelly
30047e37c4428509524ee576920a98381f3e4872493Nick PellyDESCRIPTION
30147e37c4428509524ee576920a98381f3e4872493Nick Pelly  IL Client callbacks are generated through this routine. The decoder
30247e37c4428509524ee576920a98381f3e4872493Nick Pelly  provides the thread context for this routine.
30347e37c4428509524ee576920a98381f3e4872493Nick Pelly
30447e37c4428509524ee576920a98381f3e4872493Nick PellyPARAMETERS
30547e37c4428509524ee576920a98381f3e4872493Nick Pelly  ctxt -- Context information related to the self.
30647e37c4428509524ee576920a98381f3e4872493Nick Pelly  id   -- Event identifier. This could be any of the following:
30747e37c4428509524ee576920a98381f3e4872493Nick Pelly          1. Command completion event
30847e37c4428509524ee576920a98381f3e4872493Nick Pelly          2. Buffer done callback event
30947e37c4428509524ee576920a98381f3e4872493Nick Pelly          3. Frame done callback event
31047e37c4428509524ee576920a98381f3e4872493Nick Pelly
31147e37c4428509524ee576920a98381f3e4872493Nick PellyRETURN VALUE
31247e37c4428509524ee576920a98381f3e4872493Nick Pelly  None.
31347e37c4428509524ee576920a98381f3e4872493Nick Pelly
31447e37c4428509524ee576920a98381f3e4872493Nick Pelly========================================================================== */
31547e37c4428509524ee576920a98381f3e4872493Nick Pellyvoid omx_video::process_event_cb(void *ctxt, unsigned char id)
31647e37c4428509524ee576920a98381f3e4872493Nick Pelly{
31747e37c4428509524ee576920a98381f3e4872493Nick Pelly  unsigned p1; // Parameter - 1
31847e37c4428509524ee576920a98381f3e4872493Nick Pelly  unsigned p2; // Parameter - 2
31947e37c4428509524ee576920a98381f3e4872493Nick Pelly  unsigned ident;
32047e37c4428509524ee576920a98381f3e4872493Nick Pelly  unsigned qsize=0; // qsize
32147e37c4428509524ee576920a98381f3e4872493Nick Pelly  omx_video *pThis = (omx_video *) ctxt;
32247e37c4428509524ee576920a98381f3e4872493Nick Pelly
32347e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(!pThis)
32447e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
32547e37c4428509524ee576920a98381f3e4872493Nick Pelly    DEBUG_PRINT_ERROR("ERROR:ProcessMsgCb:Context is incorrect; bailing out\n");
32647e37c4428509524ee576920a98381f3e4872493Nick Pelly    return;
32747e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
32847e37c4428509524ee576920a98381f3e4872493Nick Pelly
32947e37c4428509524ee576920a98381f3e4872493Nick Pelly  // Protect the shared queue data structure
33047e37c4428509524ee576920a98381f3e4872493Nick Pelly  do
33147e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
33247e37c4428509524ee576920a98381f3e4872493Nick Pelly    /*Read the message id's from the queue*/
33347e37c4428509524ee576920a98381f3e4872493Nick Pelly
33447e37c4428509524ee576920a98381f3e4872493Nick Pelly    pthread_mutex_lock(&pThis->m_lock);
33547e37c4428509524ee576920a98381f3e4872493Nick Pelly    qsize = pThis->m_cmd_q.m_size;
33647e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(qsize)
33747e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
33847e37c4428509524ee576920a98381f3e4872493Nick Pelly      pThis->m_cmd_q.pop_entry(&p1,&p2,&ident);
33947e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
34047e37c4428509524ee576920a98381f3e4872493Nick Pelly
34147e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(qsize == 0)
34247e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
34347e37c4428509524ee576920a98381f3e4872493Nick Pelly      qsize = pThis->m_ftb_q.m_size;
34447e37c4428509524ee576920a98381f3e4872493Nick Pelly      if(qsize)
34547e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
34647e37c4428509524ee576920a98381f3e4872493Nick Pelly        pThis->m_ftb_q.pop_entry(&p1,&p2,&ident);
34747e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
34847e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
34947e37c4428509524ee576920a98381f3e4872493Nick Pelly
35047e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(qsize == 0)
35147e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
35247e37c4428509524ee576920a98381f3e4872493Nick Pelly      qsize = pThis->m_etb_q.m_size;
35347e37c4428509524ee576920a98381f3e4872493Nick Pelly      if(qsize)
35447e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
35547e37c4428509524ee576920a98381f3e4872493Nick Pelly        pThis->m_etb_q.pop_entry(&p1,&p2,&ident);
35647e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
35747e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
35847e37c4428509524ee576920a98381f3e4872493Nick Pelly
35947e37c4428509524ee576920a98381f3e4872493Nick Pelly    pthread_mutex_unlock(&pThis->m_lock);
36047e37c4428509524ee576920a98381f3e4872493Nick Pelly
36147e37c4428509524ee576920a98381f3e4872493Nick Pelly    /*process message if we have one*/
36247e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(qsize > 0)
36347e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
36447e37c4428509524ee576920a98381f3e4872493Nick Pelly      id = ident;
36547e37c4428509524ee576920a98381f3e4872493Nick Pelly      switch(id)
36647e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
36747e37c4428509524ee576920a98381f3e4872493Nick Pelly      case OMX_COMPONENT_GENERATE_EVENT:
36847e37c4428509524ee576920a98381f3e4872493Nick Pelly        if(pThis->m_pCallbacks.EventHandler)
36947e37c4428509524ee576920a98381f3e4872493Nick Pelly        {
37047e37c4428509524ee576920a98381f3e4872493Nick Pelly          switch(p1)
37147e37c4428509524ee576920a98381f3e4872493Nick Pelly          {
37247e37c4428509524ee576920a98381f3e4872493Nick Pelly          case OMX_CommandStateSet:
37347e37c4428509524ee576920a98381f3e4872493Nick Pelly            pThis->m_state = (OMX_STATETYPE) p2;
37447e37c4428509524ee576920a98381f3e4872493Nick Pelly            DEBUG_PRINT_LOW("Process -> state set to %d \n", pThis->m_state);
37547e37c4428509524ee576920a98381f3e4872493Nick Pelly            pThis->m_pCallbacks.EventHandler(&pThis->m_cmp, pThis->m_app_data,
37647e37c4428509524ee576920a98381f3e4872493Nick Pelly                                             OMX_EventCmdComplete, p1, p2, NULL);
37747e37c4428509524ee576920a98381f3e4872493Nick Pelly            break;
37847e37c4428509524ee576920a98381f3e4872493Nick Pelly
37947e37c4428509524ee576920a98381f3e4872493Nick Pelly          case OMX_EventError:
38047e37c4428509524ee576920a98381f3e4872493Nick Pelly            DEBUG_PRINT_ERROR("\nERROR: OMX_EventError: p2 = %d\n", p2);
381826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev            if(p2 == OMX_ErrorHardware)
38247e37c4428509524ee576920a98381f3e4872493Nick Pelly            {
38347e37c4428509524ee576920a98381f3e4872493Nick Pelly              pThis->m_pCallbacks.EventHandler(&pThis->m_cmp, pThis->m_app_data,
38447e37c4428509524ee576920a98381f3e4872493Nick Pelly                                               OMX_EventError,OMX_ErrorHardware,0,NULL);
38547e37c4428509524ee576920a98381f3e4872493Nick Pelly            }
38647e37c4428509524ee576920a98381f3e4872493Nick Pelly            else
38747e37c4428509524ee576920a98381f3e4872493Nick Pelly            {
38847e37c4428509524ee576920a98381f3e4872493Nick Pelly              pThis->m_pCallbacks.EventHandler(&pThis->m_cmp, pThis->m_app_data,
38947e37c4428509524ee576920a98381f3e4872493Nick Pelly                                               OMX_EventError, p2, NULL, NULL );
39047e37c4428509524ee576920a98381f3e4872493Nick Pelly
39147e37c4428509524ee576920a98381f3e4872493Nick Pelly            }
39247e37c4428509524ee576920a98381f3e4872493Nick Pelly            break;
39347e37c4428509524ee576920a98381f3e4872493Nick Pelly
39447e37c4428509524ee576920a98381f3e4872493Nick Pelly          case OMX_CommandPortDisable:
39547e37c4428509524ee576920a98381f3e4872493Nick Pelly            DEBUG_PRINT_LOW("Process -> Port %d set to PORT_STATE_DISABLED" \
39647e37c4428509524ee576920a98381f3e4872493Nick Pelly                        "state \n", p2);
39747e37c4428509524ee576920a98381f3e4872493Nick Pelly            pThis->m_pCallbacks.EventHandler(&pThis->m_cmp, pThis->m_app_data,
39847e37c4428509524ee576920a98381f3e4872493Nick Pelly                                             OMX_EventCmdComplete, p1, p2, NULL );
39947e37c4428509524ee576920a98381f3e4872493Nick Pelly            break;
40047e37c4428509524ee576920a98381f3e4872493Nick Pelly          case OMX_CommandPortEnable:
40147e37c4428509524ee576920a98381f3e4872493Nick Pelly            DEBUG_PRINT_LOW("Process ->Port %d set PORT_STATE_ENABLED state\n" \
40247e37c4428509524ee576920a98381f3e4872493Nick Pelly                        , p2);
40347e37c4428509524ee576920a98381f3e4872493Nick Pelly            pThis->m_pCallbacks.EventHandler(&pThis->m_cmp, pThis->m_app_data,\
40447e37c4428509524ee576920a98381f3e4872493Nick Pelly                                             OMX_EventCmdComplete, p1, p2, NULL );
40547e37c4428509524ee576920a98381f3e4872493Nick Pelly            break;
40647e37c4428509524ee576920a98381f3e4872493Nick Pelly
40747e37c4428509524ee576920a98381f3e4872493Nick Pelly          default:
408826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev            DEBUG_PRINT_LOW("\n process_event_cb forwarding EventCmdComplete %d \n", p1);
40947e37c4428509524ee576920a98381f3e4872493Nick Pelly            pThis->m_pCallbacks.EventHandler(&pThis->m_cmp, pThis->m_app_data,
41047e37c4428509524ee576920a98381f3e4872493Nick Pelly                                             OMX_EventCmdComplete, p1, p2, NULL );
41147e37c4428509524ee576920a98381f3e4872493Nick Pelly            break;
41247e37c4428509524ee576920a98381f3e4872493Nick Pelly
41347e37c4428509524ee576920a98381f3e4872493Nick Pelly          }
41447e37c4428509524ee576920a98381f3e4872493Nick Pelly        }
41547e37c4428509524ee576920a98381f3e4872493Nick Pelly        else
41647e37c4428509524ee576920a98381f3e4872493Nick Pelly        {
41747e37c4428509524ee576920a98381f3e4872493Nick Pelly          DEBUG_PRINT_ERROR("ERROR: ProcessMsgCb NULL callbacks\n");
41847e37c4428509524ee576920a98381f3e4872493Nick Pelly        }
41947e37c4428509524ee576920a98381f3e4872493Nick Pelly        break;
4207eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      case OMX_COMPONENT_GENERATE_ETB_OPQ:
4217eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George        DEBUG_PRINT_LOW("OMX_COMPONENT_GENERATE_ETB_OPQ\n");
4227eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George        if(pThis->empty_this_buffer_opaque((OMX_HANDLETYPE)p1,\
4237eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George                                          (OMX_BUFFERHEADERTYPE *)p2) != OMX_ErrorNone)
4247eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George        {
4257eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George          DEBUG_PRINT_ERROR("\nERROR: ETBProxy() failed!\n");
4267eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George          pThis->omx_report_error ();
4277eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George        }
4287eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George        break;
42947e37c4428509524ee576920a98381f3e4872493Nick Pelly      case OMX_COMPONENT_GENERATE_ETB:
4307eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George        DEBUG_PRINT_LOW("OMX_COMPONENT_GENERATE_ETB\n");
43147e37c4428509524ee576920a98381f3e4872493Nick Pelly        if(pThis->empty_this_buffer_proxy((OMX_HANDLETYPE)p1,\
43247e37c4428509524ee576920a98381f3e4872493Nick Pelly                                          (OMX_BUFFERHEADERTYPE *)p2) != OMX_ErrorNone)
43347e37c4428509524ee576920a98381f3e4872493Nick Pelly        {
43447e37c4428509524ee576920a98381f3e4872493Nick Pelly          DEBUG_PRINT_ERROR("\nERROR: ETBProxy() failed!\n");
43547e37c4428509524ee576920a98381f3e4872493Nick Pelly          pThis->omx_report_error ();
43647e37c4428509524ee576920a98381f3e4872493Nick Pelly        }
43747e37c4428509524ee576920a98381f3e4872493Nick Pelly        break;
43847e37c4428509524ee576920a98381f3e4872493Nick Pelly
43947e37c4428509524ee576920a98381f3e4872493Nick Pelly      case OMX_COMPONENT_GENERATE_FTB:
44047e37c4428509524ee576920a98381f3e4872493Nick Pelly        if( pThis->fill_this_buffer_proxy((OMX_HANDLETYPE)p1,\
44147e37c4428509524ee576920a98381f3e4872493Nick Pelly                                          (OMX_BUFFERHEADERTYPE *)p2) != OMX_ErrorNone)
44247e37c4428509524ee576920a98381f3e4872493Nick Pelly        {
44347e37c4428509524ee576920a98381f3e4872493Nick Pelly          DEBUG_PRINT_ERROR("\nERROR: FTBProxy() failed!\n");
44447e37c4428509524ee576920a98381f3e4872493Nick Pelly          pThis->omx_report_error ();
44547e37c4428509524ee576920a98381f3e4872493Nick Pelly        }
44647e37c4428509524ee576920a98381f3e4872493Nick Pelly        break;
44747e37c4428509524ee576920a98381f3e4872493Nick Pelly
44847e37c4428509524ee576920a98381f3e4872493Nick Pelly      case OMX_COMPONENT_GENERATE_COMMAND:
44947e37c4428509524ee576920a98381f3e4872493Nick Pelly        pThis->send_command_proxy(&pThis->m_cmp,(OMX_COMMANDTYPE)p1,\
45047e37c4428509524ee576920a98381f3e4872493Nick Pelly                                  (OMX_U32)p2,(OMX_PTR)NULL);
45147e37c4428509524ee576920a98381f3e4872493Nick Pelly        break;
45247e37c4428509524ee576920a98381f3e4872493Nick Pelly
45347e37c4428509524ee576920a98381f3e4872493Nick Pelly      case OMX_COMPONENT_GENERATE_EBD:
45447e37c4428509524ee576920a98381f3e4872493Nick Pelly        if( pThis->empty_buffer_done(&pThis->m_cmp,
45547e37c4428509524ee576920a98381f3e4872493Nick Pelly                                     (OMX_BUFFERHEADERTYPE *)p1) != OMX_ErrorNone)
45647e37c4428509524ee576920a98381f3e4872493Nick Pelly        {
45747e37c4428509524ee576920a98381f3e4872493Nick Pelly          DEBUG_PRINT_ERROR("\nERROR: empty_buffer_done() failed!\n");
45847e37c4428509524ee576920a98381f3e4872493Nick Pelly          pThis->omx_report_error ();
45947e37c4428509524ee576920a98381f3e4872493Nick Pelly        }
46047e37c4428509524ee576920a98381f3e4872493Nick Pelly        break;
46147e37c4428509524ee576920a98381f3e4872493Nick Pelly
46247e37c4428509524ee576920a98381f3e4872493Nick Pelly      case OMX_COMPONENT_GENERATE_FBD:
46347e37c4428509524ee576920a98381f3e4872493Nick Pelly        if( pThis->fill_buffer_done(&pThis->m_cmp,
46447e37c4428509524ee576920a98381f3e4872493Nick Pelly                                    (OMX_BUFFERHEADERTYPE *)p1) != OMX_ErrorNone )
46547e37c4428509524ee576920a98381f3e4872493Nick Pelly        {
46647e37c4428509524ee576920a98381f3e4872493Nick Pelly          DEBUG_PRINT_ERROR("\nERROR: fill_buffer_done() failed!\n");
46747e37c4428509524ee576920a98381f3e4872493Nick Pelly          pThis->omx_report_error ();
46847e37c4428509524ee576920a98381f3e4872493Nick Pelly        }
46947e37c4428509524ee576920a98381f3e4872493Nick Pelly        break;
47047e37c4428509524ee576920a98381f3e4872493Nick Pelly
47147e37c4428509524ee576920a98381f3e4872493Nick Pelly      case OMX_COMPONENT_GENERATE_EVENT_INPUT_FLUSH:
47247e37c4428509524ee576920a98381f3e4872493Nick Pelly
47347e37c4428509524ee576920a98381f3e4872493Nick Pelly        pThis->input_flush_progress = false;
47447e37c4428509524ee576920a98381f3e4872493Nick Pelly        DEBUG_PRINT_HIGH("\nm_etb_count at i/p flush = %u", m_etb_count);
47547e37c4428509524ee576920a98381f3e4872493Nick Pelly        m_etb_count = 0;
47647e37c4428509524ee576920a98381f3e4872493Nick Pelly        if(pThis->m_pCallbacks.EventHandler)
47747e37c4428509524ee576920a98381f3e4872493Nick Pelly        {
47847e37c4428509524ee576920a98381f3e4872493Nick Pelly          /*Check if we need generate event for Flush done*/
47947e37c4428509524ee576920a98381f3e4872493Nick Pelly          if(BITMASK_PRESENT(&pThis->m_flags,
48047e37c4428509524ee576920a98381f3e4872493Nick Pelly                             OMX_COMPONENT_INPUT_FLUSH_PENDING))
48147e37c4428509524ee576920a98381f3e4872493Nick Pelly          {
48247e37c4428509524ee576920a98381f3e4872493Nick Pelly            BITMASK_CLEAR (&pThis->m_flags,OMX_COMPONENT_INPUT_FLUSH_PENDING);
48347e37c4428509524ee576920a98381f3e4872493Nick Pelly            pThis->m_pCallbacks.EventHandler(&pThis->m_cmp, pThis->m_app_data,
48447e37c4428509524ee576920a98381f3e4872493Nick Pelly                                             OMX_EventCmdComplete,OMX_CommandFlush,
48547e37c4428509524ee576920a98381f3e4872493Nick Pelly                                             PORT_INDEX_IN,NULL );
48647e37c4428509524ee576920a98381f3e4872493Nick Pelly          }
48747e37c4428509524ee576920a98381f3e4872493Nick Pelly          else if(BITMASK_PRESENT(&pThis->m_flags,
48847e37c4428509524ee576920a98381f3e4872493Nick Pelly                                  OMX_COMPONENT_IDLE_PENDING))
48947e37c4428509524ee576920a98381f3e4872493Nick Pelly          {
49047e37c4428509524ee576920a98381f3e4872493Nick Pelly            if(!pThis->output_flush_progress)
49147e37c4428509524ee576920a98381f3e4872493Nick Pelly            {
492826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev              DEBUG_PRINT_LOW("\n dev_stop called after input flush complete\n");
49347e37c4428509524ee576920a98381f3e4872493Nick Pelly              if(dev_stop() != 0)
49447e37c4428509524ee576920a98381f3e4872493Nick Pelly              {
49547e37c4428509524ee576920a98381f3e4872493Nick Pelly                DEBUG_PRINT_ERROR("\nERROR: dev_stop() failed in i/p flush!\n");
49647e37c4428509524ee576920a98381f3e4872493Nick Pelly                pThis->omx_report_error ();
49747e37c4428509524ee576920a98381f3e4872493Nick Pelly              }
49847e37c4428509524ee576920a98381f3e4872493Nick Pelly            }
49947e37c4428509524ee576920a98381f3e4872493Nick Pelly          }
50047e37c4428509524ee576920a98381f3e4872493Nick Pelly        }
50147e37c4428509524ee576920a98381f3e4872493Nick Pelly
50247e37c4428509524ee576920a98381f3e4872493Nick Pelly        break;
50347e37c4428509524ee576920a98381f3e4872493Nick Pelly
50447e37c4428509524ee576920a98381f3e4872493Nick Pelly      case OMX_COMPONENT_GENERATE_EVENT_OUTPUT_FLUSH:
50547e37c4428509524ee576920a98381f3e4872493Nick Pelly
50647e37c4428509524ee576920a98381f3e4872493Nick Pelly        pThis->output_flush_progress = false;
50747e37c4428509524ee576920a98381f3e4872493Nick Pelly        DEBUG_PRINT_HIGH("\nm_fbd_count at o/p flush = %u", m_fbd_count);
50847e37c4428509524ee576920a98381f3e4872493Nick Pelly        m_fbd_count = 0;
50947e37c4428509524ee576920a98381f3e4872493Nick Pelly        if(pThis->m_pCallbacks.EventHandler)
51047e37c4428509524ee576920a98381f3e4872493Nick Pelly        {
51147e37c4428509524ee576920a98381f3e4872493Nick Pelly          /*Check if we need generate event for Flush done*/
51247e37c4428509524ee576920a98381f3e4872493Nick Pelly          if(BITMASK_PRESENT(&pThis->m_flags,
51347e37c4428509524ee576920a98381f3e4872493Nick Pelly                             OMX_COMPONENT_OUTPUT_FLUSH_PENDING))
51447e37c4428509524ee576920a98381f3e4872493Nick Pelly          {
51547e37c4428509524ee576920a98381f3e4872493Nick Pelly            BITMASK_CLEAR (&pThis->m_flags,OMX_COMPONENT_OUTPUT_FLUSH_PENDING);
51647e37c4428509524ee576920a98381f3e4872493Nick Pelly
51747e37c4428509524ee576920a98381f3e4872493Nick Pelly            pThis->m_pCallbacks.EventHandler(&pThis->m_cmp, pThis->m_app_data,
51847e37c4428509524ee576920a98381f3e4872493Nick Pelly                                             OMX_EventCmdComplete,OMX_CommandFlush,
51947e37c4428509524ee576920a98381f3e4872493Nick Pelly                                             PORT_INDEX_OUT,NULL );
52047e37c4428509524ee576920a98381f3e4872493Nick Pelly          }
52147e37c4428509524ee576920a98381f3e4872493Nick Pelly          else if(BITMASK_PRESENT(&pThis->m_flags ,OMX_COMPONENT_IDLE_PENDING))
52247e37c4428509524ee576920a98381f3e4872493Nick Pelly          {
523826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev            DEBUG_PRINT_LOW("\n dev_stop called after Output flush complete\n");
52447e37c4428509524ee576920a98381f3e4872493Nick Pelly            if(!pThis->input_flush_progress)
52547e37c4428509524ee576920a98381f3e4872493Nick Pelly            {
52647e37c4428509524ee576920a98381f3e4872493Nick Pelly              if(dev_stop() != 0)
52747e37c4428509524ee576920a98381f3e4872493Nick Pelly              {
52847e37c4428509524ee576920a98381f3e4872493Nick Pelly                DEBUG_PRINT_ERROR("\nERROR: dev_stop() failed in o/p flush!\n");
52947e37c4428509524ee576920a98381f3e4872493Nick Pelly                pThis->omx_report_error ();
53047e37c4428509524ee576920a98381f3e4872493Nick Pelly              }
53147e37c4428509524ee576920a98381f3e4872493Nick Pelly            }
53247e37c4428509524ee576920a98381f3e4872493Nick Pelly          }
53347e37c4428509524ee576920a98381f3e4872493Nick Pelly        }
53447e37c4428509524ee576920a98381f3e4872493Nick Pelly        break;
53547e37c4428509524ee576920a98381f3e4872493Nick Pelly
53647e37c4428509524ee576920a98381f3e4872493Nick Pelly      case OMX_COMPONENT_GENERATE_START_DONE:
53747e37c4428509524ee576920a98381f3e4872493Nick Pelly        DEBUG_PRINT_LOW("\n OMX_COMPONENT_GENERATE_START_DONE msg");
53847e37c4428509524ee576920a98381f3e4872493Nick Pelly
53947e37c4428509524ee576920a98381f3e4872493Nick Pelly        if(pThis->m_pCallbacks.EventHandler)
54047e37c4428509524ee576920a98381f3e4872493Nick Pelly        {
54147e37c4428509524ee576920a98381f3e4872493Nick Pelly          DEBUG_PRINT_LOW("\n OMX_COMPONENT_GENERATE_START_DONE Success");
54247e37c4428509524ee576920a98381f3e4872493Nick Pelly          if(BITMASK_PRESENT(&pThis->m_flags,OMX_COMPONENT_EXECUTE_PENDING))
54347e37c4428509524ee576920a98381f3e4872493Nick Pelly          {
54447e37c4428509524ee576920a98381f3e4872493Nick Pelly            DEBUG_PRINT_LOW("\n OMX_COMPONENT_GENERATE_START_DONE Move to \
54547e37c4428509524ee576920a98381f3e4872493Nick Pelly                             executing");
54647e37c4428509524ee576920a98381f3e4872493Nick Pelly            // Send the callback now
54747e37c4428509524ee576920a98381f3e4872493Nick Pelly            BITMASK_CLEAR((&pThis->m_flags),OMX_COMPONENT_EXECUTE_PENDING);
54847e37c4428509524ee576920a98381f3e4872493Nick Pelly            pThis->m_state = OMX_StateExecuting;
54947e37c4428509524ee576920a98381f3e4872493Nick Pelly            pThis->m_pCallbacks.EventHandler(&pThis->m_cmp, pThis->m_app_data,
55047e37c4428509524ee576920a98381f3e4872493Nick Pelly                                             OMX_EventCmdComplete,OMX_CommandStateSet,
55147e37c4428509524ee576920a98381f3e4872493Nick Pelly                                             OMX_StateExecuting, NULL);
55247e37c4428509524ee576920a98381f3e4872493Nick Pelly          }
55347e37c4428509524ee576920a98381f3e4872493Nick Pelly          else if(BITMASK_PRESENT(&pThis->m_flags,
55447e37c4428509524ee576920a98381f3e4872493Nick Pelly                                  OMX_COMPONENT_PAUSE_PENDING))
55547e37c4428509524ee576920a98381f3e4872493Nick Pelly          {
55647e37c4428509524ee576920a98381f3e4872493Nick Pelly            if(dev_pause())
55747e37c4428509524ee576920a98381f3e4872493Nick Pelly            {
55847e37c4428509524ee576920a98381f3e4872493Nick Pelly              DEBUG_PRINT_ERROR("\nERROR: dev_pause() failed in Start Done!\n");
55947e37c4428509524ee576920a98381f3e4872493Nick Pelly              pThis->omx_report_error ();
56047e37c4428509524ee576920a98381f3e4872493Nick Pelly            }
56147e37c4428509524ee576920a98381f3e4872493Nick Pelly          }
562826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev          else if (BITMASK_PRESENT(&pThis->m_flags,
563826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev                                   OMX_COMPONENT_LOADED_START_PENDING))
564826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev          {
565826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev            if(dev_loaded_start_done())
566826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev            {
567826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev              DEBUG_PRINT_LOW("successful loaded Start Done!");
568826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev            }
569826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev            else
570826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev            {
571826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev              DEBUG_PRINT_ERROR("ERROR: failed in loaded Start Done!");
572826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev              pThis->omx_report_error ();
573826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev            }
574826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev            BITMASK_CLEAR((&pThis->m_flags),OMX_COMPONENT_LOADED_START_PENDING);
575826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev          }
576826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev          else
577826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev          {
578826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev            DEBUG_PRINT_ERROR("\nERROR: unknown flags=%x\n",pThis->m_flags);
579826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev          }
58047e37c4428509524ee576920a98381f3e4872493Nick Pelly        }
58147e37c4428509524ee576920a98381f3e4872493Nick Pelly        else
58247e37c4428509524ee576920a98381f3e4872493Nick Pelly        {
58347e37c4428509524ee576920a98381f3e4872493Nick Pelly          DEBUG_PRINT_LOW("\n Event Handler callback is NULL");
58447e37c4428509524ee576920a98381f3e4872493Nick Pelly        }
58547e37c4428509524ee576920a98381f3e4872493Nick Pelly        break;
58647e37c4428509524ee576920a98381f3e4872493Nick Pelly
58747e37c4428509524ee576920a98381f3e4872493Nick Pelly      case OMX_COMPONENT_GENERATE_PAUSE_DONE:
58847e37c4428509524ee576920a98381f3e4872493Nick Pelly        DEBUG_PRINT_LOW("\n OMX_COMPONENT_GENERATE_PAUSE_DONE msg");
58947e37c4428509524ee576920a98381f3e4872493Nick Pelly        if(pThis->m_pCallbacks.EventHandler)
59047e37c4428509524ee576920a98381f3e4872493Nick Pelly        {
59147e37c4428509524ee576920a98381f3e4872493Nick Pelly          if(BITMASK_PRESENT(&pThis->m_flags,OMX_COMPONENT_PAUSE_PENDING))
59247e37c4428509524ee576920a98381f3e4872493Nick Pelly          {
59347e37c4428509524ee576920a98381f3e4872493Nick Pelly            //Send the callback now
594826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev            pThis->complete_pending_buffer_done_cbs();
595826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev            DEBUG_PRINT_LOW("omx_video::process_event_cb() Sending PAUSE complete after all pending EBD/FBD\n");
59647e37c4428509524ee576920a98381f3e4872493Nick Pelly            BITMASK_CLEAR((&pThis->m_flags),OMX_COMPONENT_PAUSE_PENDING);
59747e37c4428509524ee576920a98381f3e4872493Nick Pelly            pThis->m_state = OMX_StatePause;
59847e37c4428509524ee576920a98381f3e4872493Nick Pelly            pThis->m_pCallbacks.EventHandler(&pThis->m_cmp, pThis->m_app_data,
59947e37c4428509524ee576920a98381f3e4872493Nick Pelly                                             OMX_EventCmdComplete,OMX_CommandStateSet,
60047e37c4428509524ee576920a98381f3e4872493Nick Pelly                                             OMX_StatePause, NULL);
60147e37c4428509524ee576920a98381f3e4872493Nick Pelly          }
60247e37c4428509524ee576920a98381f3e4872493Nick Pelly        }
60347e37c4428509524ee576920a98381f3e4872493Nick Pelly
60447e37c4428509524ee576920a98381f3e4872493Nick Pelly        break;
60547e37c4428509524ee576920a98381f3e4872493Nick Pelly
60647e37c4428509524ee576920a98381f3e4872493Nick Pelly      case OMX_COMPONENT_GENERATE_RESUME_DONE:
60747e37c4428509524ee576920a98381f3e4872493Nick Pelly        DEBUG_PRINT_LOW("\n OMX_COMPONENT_GENERATE_RESUME_DONE msg");
60847e37c4428509524ee576920a98381f3e4872493Nick Pelly        if(pThis->m_pCallbacks.EventHandler)
60947e37c4428509524ee576920a98381f3e4872493Nick Pelly        {
61047e37c4428509524ee576920a98381f3e4872493Nick Pelly          if(BITMASK_PRESENT(&pThis->m_flags,OMX_COMPONENT_EXECUTE_PENDING))
61147e37c4428509524ee576920a98381f3e4872493Nick Pelly          {
61247e37c4428509524ee576920a98381f3e4872493Nick Pelly            // Send the callback now
61347e37c4428509524ee576920a98381f3e4872493Nick Pelly            BITMASK_CLEAR((&pThis->m_flags),OMX_COMPONENT_EXECUTE_PENDING);
61447e37c4428509524ee576920a98381f3e4872493Nick Pelly            pThis->m_state = OMX_StateExecuting;
61547e37c4428509524ee576920a98381f3e4872493Nick Pelly            pThis->m_pCallbacks.EventHandler(&pThis->m_cmp, pThis->m_app_data,
61647e37c4428509524ee576920a98381f3e4872493Nick Pelly                                             OMX_EventCmdComplete,OMX_CommandStateSet,
61747e37c4428509524ee576920a98381f3e4872493Nick Pelly                                             OMX_StateExecuting,NULL);
61847e37c4428509524ee576920a98381f3e4872493Nick Pelly          }
61947e37c4428509524ee576920a98381f3e4872493Nick Pelly        }
62047e37c4428509524ee576920a98381f3e4872493Nick Pelly
62147e37c4428509524ee576920a98381f3e4872493Nick Pelly        break;
62247e37c4428509524ee576920a98381f3e4872493Nick Pelly
62347e37c4428509524ee576920a98381f3e4872493Nick Pelly      case OMX_COMPONENT_GENERATE_STOP_DONE:
62447e37c4428509524ee576920a98381f3e4872493Nick Pelly        DEBUG_PRINT_LOW("\n OMX_COMPONENT_GENERATE_STOP_DONE msg");
62547e37c4428509524ee576920a98381f3e4872493Nick Pelly        if(pThis->m_pCallbacks.EventHandler)
62647e37c4428509524ee576920a98381f3e4872493Nick Pelly        {
627826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev          pThis->complete_pending_buffer_done_cbs();
62847e37c4428509524ee576920a98381f3e4872493Nick Pelly          if(BITMASK_PRESENT(&pThis->m_flags,OMX_COMPONENT_IDLE_PENDING))
62947e37c4428509524ee576920a98381f3e4872493Nick Pelly          {
63047e37c4428509524ee576920a98381f3e4872493Nick Pelly            // Send the callback now
63147e37c4428509524ee576920a98381f3e4872493Nick Pelly            BITMASK_CLEAR((&pThis->m_flags),OMX_COMPONENT_IDLE_PENDING);
63247e37c4428509524ee576920a98381f3e4872493Nick Pelly            pThis->m_state = OMX_StateIdle;
63347e37c4428509524ee576920a98381f3e4872493Nick Pelly            pThis->m_pCallbacks.EventHandler(&pThis->m_cmp,pThis->m_app_data,
63447e37c4428509524ee576920a98381f3e4872493Nick Pelly                                             OMX_EventCmdComplete,OMX_CommandStateSet,
63547e37c4428509524ee576920a98381f3e4872493Nick Pelly                                             OMX_StateIdle,NULL);
63647e37c4428509524ee576920a98381f3e4872493Nick Pelly          }
637826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev          else if (BITMASK_PRESENT(&pThis->m_flags,
638826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev                                   OMX_COMPONENT_LOADED_STOP_PENDING))
639826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev          {
640826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev            if(dev_loaded_stop_done())
641826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev            {
642826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev              DEBUG_PRINT_LOW("successful loaded Stop Done!");
643826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev            }
644826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev            else
645826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev            {
646826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev              DEBUG_PRINT_ERROR("ERROR: failed in loaded Stop Done!");
647826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev              pThis->omx_report_error ();
648826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev            }
649826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev            BITMASK_CLEAR((&pThis->m_flags),OMX_COMPONENT_LOADED_STOP_PENDING);
650826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev          }
651826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev          else
652826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev          {
653826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev            DEBUG_PRINT_ERROR("\nERROR: unknown flags=%x\n",pThis->m_flags);
654826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev          }
65547e37c4428509524ee576920a98381f3e4872493Nick Pelly        }
65647e37c4428509524ee576920a98381f3e4872493Nick Pelly
65747e37c4428509524ee576920a98381f3e4872493Nick Pelly        break;
65847e37c4428509524ee576920a98381f3e4872493Nick Pelly
65947e37c4428509524ee576920a98381f3e4872493Nick Pelly      case OMX_COMPONENT_GENERATE_HARDWARE_ERROR:
66047e37c4428509524ee576920a98381f3e4872493Nick Pelly        DEBUG_PRINT_ERROR("\nERROR: OMX_COMPONENT_GENERATE_HARDWARE_ERROR!\n");
66147e37c4428509524ee576920a98381f3e4872493Nick Pelly        pThis->omx_report_error ();
66247e37c4428509524ee576920a98381f3e4872493Nick Pelly        break;
66347e37c4428509524ee576920a98381f3e4872493Nick Pelly
66447e37c4428509524ee576920a98381f3e4872493Nick Pelly      default:
665826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        DEBUG_PRINT_LOW("\n process_event_cb unknown msg id 0x%02x", id);
66647e37c4428509524ee576920a98381f3e4872493Nick Pelly        break;
66747e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
66847e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
66947e37c4428509524ee576920a98381f3e4872493Nick Pelly
67047e37c4428509524ee576920a98381f3e4872493Nick Pelly    pthread_mutex_lock(&pThis->m_lock);
67147e37c4428509524ee576920a98381f3e4872493Nick Pelly    qsize = pThis->m_cmd_q.m_size + pThis->m_ftb_q.m_size +\
67247e37c4428509524ee576920a98381f3e4872493Nick Pelly            pThis->m_etb_q.m_size;
67347e37c4428509524ee576920a98381f3e4872493Nick Pelly
67447e37c4428509524ee576920a98381f3e4872493Nick Pelly    pthread_mutex_unlock(&pThis->m_lock);
67547e37c4428509524ee576920a98381f3e4872493Nick Pelly
67647e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
67747e37c4428509524ee576920a98381f3e4872493Nick Pelly  while(qsize>0);
678826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  DEBUG_PRINT_LOW("\n exited the while loop\n");
67947e37c4428509524ee576920a98381f3e4872493Nick Pelly
68047e37c4428509524ee576920a98381f3e4872493Nick Pelly}
68147e37c4428509524ee576920a98381f3e4872493Nick Pelly
68247e37c4428509524ee576920a98381f3e4872493Nick Pelly
68347e37c4428509524ee576920a98381f3e4872493Nick Pelly
68447e37c4428509524ee576920a98381f3e4872493Nick Pelly
68547e37c4428509524ee576920a98381f3e4872493Nick Pelly/* ======================================================================
68647e37c4428509524ee576920a98381f3e4872493Nick PellyFUNCTION
68747e37c4428509524ee576920a98381f3e4872493Nick Pelly  omx_venc::GetComponentVersion
68847e37c4428509524ee576920a98381f3e4872493Nick Pelly
68947e37c4428509524ee576920a98381f3e4872493Nick PellyDESCRIPTION
69047e37c4428509524ee576920a98381f3e4872493Nick Pelly  Returns the component version.
69147e37c4428509524ee576920a98381f3e4872493Nick Pelly
69247e37c4428509524ee576920a98381f3e4872493Nick PellyPARAMETERS
69347e37c4428509524ee576920a98381f3e4872493Nick Pelly  TBD.
69447e37c4428509524ee576920a98381f3e4872493Nick Pelly
69547e37c4428509524ee576920a98381f3e4872493Nick PellyRETURN VALUE
69647e37c4428509524ee576920a98381f3e4872493Nick Pelly  OMX_ErrorNone.
69747e37c4428509524ee576920a98381f3e4872493Nick Pelly
69847e37c4428509524ee576920a98381f3e4872493Nick Pelly========================================================================== */
69947e37c4428509524ee576920a98381f3e4872493Nick PellyOMX_ERRORTYPE  omx_video::get_component_version
70047e37c4428509524ee576920a98381f3e4872493Nick Pelly(
70147e37c4428509524ee576920a98381f3e4872493Nick PellyOMX_IN OMX_HANDLETYPE hComp,
70247e37c4428509524ee576920a98381f3e4872493Nick PellyOMX_OUT OMX_STRING componentName,
70347e37c4428509524ee576920a98381f3e4872493Nick PellyOMX_OUT OMX_VERSIONTYPE* componentVersion,
70447e37c4428509524ee576920a98381f3e4872493Nick PellyOMX_OUT OMX_VERSIONTYPE* specVersion,
70547e37c4428509524ee576920a98381f3e4872493Nick PellyOMX_OUT OMX_UUIDTYPE* componentUUID
70647e37c4428509524ee576920a98381f3e4872493Nick Pelly)
70747e37c4428509524ee576920a98381f3e4872493Nick Pelly{
70847e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(m_state == OMX_StateInvalid)
70947e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
71047e37c4428509524ee576920a98381f3e4872493Nick Pelly    DEBUG_PRINT_ERROR("ERROR: Get Comp Version in Invalid State\n");
71147e37c4428509524ee576920a98381f3e4872493Nick Pelly    return OMX_ErrorInvalidState;
71247e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
71347e37c4428509524ee576920a98381f3e4872493Nick Pelly  /* TBD -- Return the proper version */
714826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  if (specVersion)
715826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  {
716826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    specVersion->nVersion = OMX_SPEC_VERSION;
717826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  }
71847e37c4428509524ee576920a98381f3e4872493Nick Pelly  return OMX_ErrorNone;
71947e37c4428509524ee576920a98381f3e4872493Nick Pelly}
72047e37c4428509524ee576920a98381f3e4872493Nick Pelly/* ======================================================================
72147e37c4428509524ee576920a98381f3e4872493Nick PellyFUNCTION
72247e37c4428509524ee576920a98381f3e4872493Nick Pelly  omx_venc::SendCommand
72347e37c4428509524ee576920a98381f3e4872493Nick Pelly
72447e37c4428509524ee576920a98381f3e4872493Nick PellyDESCRIPTION
72547e37c4428509524ee576920a98381f3e4872493Nick Pelly  Returns zero if all the buffers released..
72647e37c4428509524ee576920a98381f3e4872493Nick Pelly
72747e37c4428509524ee576920a98381f3e4872493Nick PellyPARAMETERS
72847e37c4428509524ee576920a98381f3e4872493Nick Pelly  None.
72947e37c4428509524ee576920a98381f3e4872493Nick Pelly
73047e37c4428509524ee576920a98381f3e4872493Nick PellyRETURN VALUE
73147e37c4428509524ee576920a98381f3e4872493Nick Pelly  true/false
73247e37c4428509524ee576920a98381f3e4872493Nick Pelly
73347e37c4428509524ee576920a98381f3e4872493Nick Pelly========================================================================== */
73447e37c4428509524ee576920a98381f3e4872493Nick PellyOMX_ERRORTYPE  omx_video::send_command(OMX_IN OMX_HANDLETYPE hComp,
73547e37c4428509524ee576920a98381f3e4872493Nick Pelly                                       OMX_IN OMX_COMMANDTYPE cmd,
73647e37c4428509524ee576920a98381f3e4872493Nick Pelly                                       OMX_IN OMX_U32 param1,
73747e37c4428509524ee576920a98381f3e4872493Nick Pelly                                       OMX_IN OMX_PTR cmdData
73847e37c4428509524ee576920a98381f3e4872493Nick Pelly                                      )
73947e37c4428509524ee576920a98381f3e4872493Nick Pelly{
74047e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(m_state == OMX_StateInvalid)
74147e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
74247e37c4428509524ee576920a98381f3e4872493Nick Pelly    DEBUG_PRINT_ERROR("ERROR: Send Command in Invalid State\n");
74347e37c4428509524ee576920a98381f3e4872493Nick Pelly    return OMX_ErrorInvalidState;
74447e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
74547e37c4428509524ee576920a98381f3e4872493Nick Pelly
74647e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(cmd == OMX_CommandFlush || cmd == OMX_CommandPortDisable || cmd == OMX_CommandPortEnable)
74747e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
74847e37c4428509524ee576920a98381f3e4872493Nick Pelly    if((param1 != PORT_INDEX_IN) && (param1 != PORT_INDEX_OUT) && (param1 != PORT_INDEX_BOTH))
74947e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
75047e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_ERROR("ERROR: omx_video::send_command-->bad port index\n");
75147e37c4428509524ee576920a98381f3e4872493Nick Pelly      return OMX_ErrorBadPortIndex;
75247e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
75347e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
75447e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(cmd == OMX_CommandMarkBuffer)
75547e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
75647e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(param1 != PORT_INDEX_IN)
75747e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
75847e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_ERROR("ERROR: omx_video::send_command-->bad port index \n");
75947e37c4428509524ee576920a98381f3e4872493Nick Pelly      return OMX_ErrorBadPortIndex;
76047e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
76147e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(!cmdData)
76247e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
76347e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_ERROR("ERROR: omx_video::send_command-->param is null");
76447e37c4428509524ee576920a98381f3e4872493Nick Pelly      return OMX_ErrorBadParameter;
76547e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
76647e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
76747e37c4428509524ee576920a98381f3e4872493Nick Pelly
76847e37c4428509524ee576920a98381f3e4872493Nick Pelly  post_event((unsigned)cmd,(unsigned)param1,OMX_COMPONENT_GENERATE_COMMAND);
76947e37c4428509524ee576920a98381f3e4872493Nick Pelly  sem_wait(&m_cmd_lock);
77047e37c4428509524ee576920a98381f3e4872493Nick Pelly  return OMX_ErrorNone;
77147e37c4428509524ee576920a98381f3e4872493Nick Pelly}
77247e37c4428509524ee576920a98381f3e4872493Nick Pelly
77347e37c4428509524ee576920a98381f3e4872493Nick Pelly/* ======================================================================
77447e37c4428509524ee576920a98381f3e4872493Nick PellyFUNCTION
77547e37c4428509524ee576920a98381f3e4872493Nick Pelly  omx_venc::SendCommand
77647e37c4428509524ee576920a98381f3e4872493Nick Pelly
77747e37c4428509524ee576920a98381f3e4872493Nick PellyDESCRIPTION
77847e37c4428509524ee576920a98381f3e4872493Nick Pelly  Returns zero if all the buffers released..
77947e37c4428509524ee576920a98381f3e4872493Nick Pelly
78047e37c4428509524ee576920a98381f3e4872493Nick PellyPARAMETERS
78147e37c4428509524ee576920a98381f3e4872493Nick Pelly  None.
78247e37c4428509524ee576920a98381f3e4872493Nick Pelly
78347e37c4428509524ee576920a98381f3e4872493Nick PellyRETURN VALUE
78447e37c4428509524ee576920a98381f3e4872493Nick Pelly  true/false
78547e37c4428509524ee576920a98381f3e4872493Nick Pelly
78647e37c4428509524ee576920a98381f3e4872493Nick Pelly========================================================================== */
78747e37c4428509524ee576920a98381f3e4872493Nick PellyOMX_ERRORTYPE  omx_video::send_command_proxy(OMX_IN OMX_HANDLETYPE hComp,
78847e37c4428509524ee576920a98381f3e4872493Nick Pelly                                             OMX_IN OMX_COMMANDTYPE cmd,
78947e37c4428509524ee576920a98381f3e4872493Nick Pelly                                             OMX_IN OMX_U32 param1,
79047e37c4428509524ee576920a98381f3e4872493Nick Pelly                                             OMX_IN OMX_PTR cmdData
79147e37c4428509524ee576920a98381f3e4872493Nick Pelly                                            )
79247e37c4428509524ee576920a98381f3e4872493Nick Pelly{
79347e37c4428509524ee576920a98381f3e4872493Nick Pelly  OMX_ERRORTYPE eRet = OMX_ErrorNone;
79447e37c4428509524ee576920a98381f3e4872493Nick Pelly  OMX_STATETYPE eState = (OMX_STATETYPE) param1;
79547e37c4428509524ee576920a98381f3e4872493Nick Pelly  int bFlag = 1;
79647e37c4428509524ee576920a98381f3e4872493Nick Pelly
79747e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(cmd == OMX_CommandStateSet)
79847e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
79947e37c4428509524ee576920a98381f3e4872493Nick Pelly    /***************************/
80047e37c4428509524ee576920a98381f3e4872493Nick Pelly    /* Current State is Loaded */
80147e37c4428509524ee576920a98381f3e4872493Nick Pelly    /***************************/
80247e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(m_state == OMX_StateLoaded)
80347e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
80447e37c4428509524ee576920a98381f3e4872493Nick Pelly      if(eState == OMX_StateIdle)
80547e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
80647e37c4428509524ee576920a98381f3e4872493Nick Pelly        //if all buffers are allocated or all ports disabled
80747e37c4428509524ee576920a98381f3e4872493Nick Pelly        if(allocate_done() ||
80847e37c4428509524ee576920a98381f3e4872493Nick Pelly           ( m_sInPortDef.bEnabled == OMX_FALSE && m_sOutPortDef.bEnabled == OMX_FALSE))
80947e37c4428509524ee576920a98381f3e4872493Nick Pelly        {
81047e37c4428509524ee576920a98381f3e4872493Nick Pelly          DEBUG_PRINT_LOW("OMXCORE-SM: Loaded-->Idle\n");
81147e37c4428509524ee576920a98381f3e4872493Nick Pelly        }
81247e37c4428509524ee576920a98381f3e4872493Nick Pelly        else
81347e37c4428509524ee576920a98381f3e4872493Nick Pelly        {
81447e37c4428509524ee576920a98381f3e4872493Nick Pelly          DEBUG_PRINT_LOW("OMXCORE-SM: Loaded-->Idle-Pending\n");
81547e37c4428509524ee576920a98381f3e4872493Nick Pelly          BITMASK_SET(&m_flags, OMX_COMPONENT_IDLE_PENDING);
81647e37c4428509524ee576920a98381f3e4872493Nick Pelly          // Skip the event notification
81747e37c4428509524ee576920a98381f3e4872493Nick Pelly          bFlag = 0;
81847e37c4428509524ee576920a98381f3e4872493Nick Pelly        }
81947e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
82047e37c4428509524ee576920a98381f3e4872493Nick Pelly      /* Requesting transition from Loaded to Loaded */
82147e37c4428509524ee576920a98381f3e4872493Nick Pelly      else if(eState == OMX_StateLoaded)
82247e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
82347e37c4428509524ee576920a98381f3e4872493Nick Pelly        DEBUG_PRINT_ERROR("ERROR: OMXCORE-SM: Loaded-->Loaded\n");
82447e37c4428509524ee576920a98381f3e4872493Nick Pelly        post_event(OMX_EventError,OMX_ErrorSameState,\
82547e37c4428509524ee576920a98381f3e4872493Nick Pelly                   OMX_COMPONENT_GENERATE_EVENT);
82647e37c4428509524ee576920a98381f3e4872493Nick Pelly        eRet = OMX_ErrorSameState;
82747e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
82847e37c4428509524ee576920a98381f3e4872493Nick Pelly      /* Requesting transition from Loaded to WaitForResources */
82947e37c4428509524ee576920a98381f3e4872493Nick Pelly      else if(eState == OMX_StateWaitForResources)
83047e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
83147e37c4428509524ee576920a98381f3e4872493Nick Pelly        /* Since error is None , we will post an event
83247e37c4428509524ee576920a98381f3e4872493Nick Pelly           at the end of this function definition */
83347e37c4428509524ee576920a98381f3e4872493Nick Pelly        DEBUG_PRINT_LOW("OMXCORE-SM: Loaded-->WaitForResources\n");
83447e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
83547e37c4428509524ee576920a98381f3e4872493Nick Pelly      /* Requesting transition from Loaded to Executing */
83647e37c4428509524ee576920a98381f3e4872493Nick Pelly      else if(eState == OMX_StateExecuting)
83747e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
83847e37c4428509524ee576920a98381f3e4872493Nick Pelly        DEBUG_PRINT_ERROR("ERROR: OMXCORE-SM: Loaded-->Executing\n");
83947e37c4428509524ee576920a98381f3e4872493Nick Pelly        post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\
84047e37c4428509524ee576920a98381f3e4872493Nick Pelly                   OMX_COMPONENT_GENERATE_EVENT);
84147e37c4428509524ee576920a98381f3e4872493Nick Pelly        eRet = OMX_ErrorIncorrectStateTransition;
84247e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
84347e37c4428509524ee576920a98381f3e4872493Nick Pelly      /* Requesting transition from Loaded to Pause */
84447e37c4428509524ee576920a98381f3e4872493Nick Pelly      else if(eState == OMX_StatePause)
84547e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
84647e37c4428509524ee576920a98381f3e4872493Nick Pelly        DEBUG_PRINT_ERROR("ERROR: OMXCORE-SM: Loaded-->Pause\n");
84747e37c4428509524ee576920a98381f3e4872493Nick Pelly        post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\
84847e37c4428509524ee576920a98381f3e4872493Nick Pelly                   OMX_COMPONENT_GENERATE_EVENT);
84947e37c4428509524ee576920a98381f3e4872493Nick Pelly        eRet = OMX_ErrorIncorrectStateTransition;
85047e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
85147e37c4428509524ee576920a98381f3e4872493Nick Pelly      /* Requesting transition from Loaded to Invalid */
85247e37c4428509524ee576920a98381f3e4872493Nick Pelly      else if(eState == OMX_StateInvalid)
85347e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
85447e37c4428509524ee576920a98381f3e4872493Nick Pelly        DEBUG_PRINT_ERROR("ERROR: OMXCORE-SM: Loaded-->Invalid\n");
85547e37c4428509524ee576920a98381f3e4872493Nick Pelly        post_event(OMX_EventError,eState,OMX_COMPONENT_GENERATE_EVENT);
85647e37c4428509524ee576920a98381f3e4872493Nick Pelly        eRet = OMX_ErrorInvalidState;
85747e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
85847e37c4428509524ee576920a98381f3e4872493Nick Pelly      else
85947e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
860826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        DEBUG_PRINT_ERROR("ERROR: OMXCORE-SM: Loaded-->%d Not Handled\n",\
86147e37c4428509524ee576920a98381f3e4872493Nick Pelly                          eState);
86247e37c4428509524ee576920a98381f3e4872493Nick Pelly        eRet = OMX_ErrorBadParameter;
86347e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
86447e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
86547e37c4428509524ee576920a98381f3e4872493Nick Pelly
86647e37c4428509524ee576920a98381f3e4872493Nick Pelly    /***************************/
86747e37c4428509524ee576920a98381f3e4872493Nick Pelly    /* Current State is IDLE */
86847e37c4428509524ee576920a98381f3e4872493Nick Pelly    /***************************/
86947e37c4428509524ee576920a98381f3e4872493Nick Pelly    else if(m_state == OMX_StateIdle)
87047e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
87147e37c4428509524ee576920a98381f3e4872493Nick Pelly      if(eState == OMX_StateLoaded)
87247e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
87347e37c4428509524ee576920a98381f3e4872493Nick Pelly        if(release_done())
87447e37c4428509524ee576920a98381f3e4872493Nick Pelly        {
87547e37c4428509524ee576920a98381f3e4872493Nick Pelly          /*
87647e37c4428509524ee576920a98381f3e4872493Nick Pelly             Since error is None , we will post an event at the end
87747e37c4428509524ee576920a98381f3e4872493Nick Pelly             of this function definition
87847e37c4428509524ee576920a98381f3e4872493Nick Pelly          */
87947e37c4428509524ee576920a98381f3e4872493Nick Pelly          DEBUG_PRINT_LOW("OMXCORE-SM: Idle-->Loaded\n");
88047e37c4428509524ee576920a98381f3e4872493Nick Pelly          if(dev_stop() != 0)
88147e37c4428509524ee576920a98381f3e4872493Nick Pelly          {
88247e37c4428509524ee576920a98381f3e4872493Nick Pelly            DEBUG_PRINT_ERROR("\nERROR: dev_stop() failed at Idle --> Loaded");
88347e37c4428509524ee576920a98381f3e4872493Nick Pelly            eRet = OMX_ErrorHardware;
88447e37c4428509524ee576920a98381f3e4872493Nick Pelly          }
88547e37c4428509524ee576920a98381f3e4872493Nick Pelly        }
88647e37c4428509524ee576920a98381f3e4872493Nick Pelly        else
88747e37c4428509524ee576920a98381f3e4872493Nick Pelly        {
88847e37c4428509524ee576920a98381f3e4872493Nick Pelly          DEBUG_PRINT_LOW("OMXCORE-SM: Idle-->Loaded-Pending\n");
88947e37c4428509524ee576920a98381f3e4872493Nick Pelly          BITMASK_SET(&m_flags, OMX_COMPONENT_LOADING_PENDING);
89047e37c4428509524ee576920a98381f3e4872493Nick Pelly          // Skip the event notification
89147e37c4428509524ee576920a98381f3e4872493Nick Pelly          bFlag = 0;
89247e37c4428509524ee576920a98381f3e4872493Nick Pelly        }
89347e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
89447e37c4428509524ee576920a98381f3e4872493Nick Pelly      /* Requesting transition from Idle to Executing */
89547e37c4428509524ee576920a98381f3e4872493Nick Pelly      else if(eState == OMX_StateExecuting)
89647e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
89747e37c4428509524ee576920a98381f3e4872493Nick Pelly        if( dev_start() )
89847e37c4428509524ee576920a98381f3e4872493Nick Pelly        {
89947e37c4428509524ee576920a98381f3e4872493Nick Pelly          DEBUG_PRINT_ERROR("\nERROR: dev_start() failed in SCP on Idle --> Exe\n");
90047e37c4428509524ee576920a98381f3e4872493Nick Pelly          omx_report_error ();
90147e37c4428509524ee576920a98381f3e4872493Nick Pelly          eRet = OMX_ErrorHardware;
90247e37c4428509524ee576920a98381f3e4872493Nick Pelly        }
90347e37c4428509524ee576920a98381f3e4872493Nick Pelly        else
90447e37c4428509524ee576920a98381f3e4872493Nick Pelly        {
90547e37c4428509524ee576920a98381f3e4872493Nick Pelly          BITMASK_SET(&m_flags,OMX_COMPONENT_EXECUTE_PENDING);
90647e37c4428509524ee576920a98381f3e4872493Nick Pelly          DEBUG_PRINT_LOW("OMXCORE-SM: Idle-->Executing\n");
90747e37c4428509524ee576920a98381f3e4872493Nick Pelly          bFlag = 0;
90847e37c4428509524ee576920a98381f3e4872493Nick Pelly        }
90947e37c4428509524ee576920a98381f3e4872493Nick Pelly
910826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev	dev_start_done();
91147e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
91247e37c4428509524ee576920a98381f3e4872493Nick Pelly      /* Requesting transition from Idle to Idle */
91347e37c4428509524ee576920a98381f3e4872493Nick Pelly      else if(eState == OMX_StateIdle)
91447e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
91547e37c4428509524ee576920a98381f3e4872493Nick Pelly        DEBUG_PRINT_ERROR("ERROR: OMXCORE-SM: Idle-->Idle\n");
91647e37c4428509524ee576920a98381f3e4872493Nick Pelly        post_event(OMX_EventError,OMX_ErrorSameState,\
91747e37c4428509524ee576920a98381f3e4872493Nick Pelly                   OMX_COMPONENT_GENERATE_EVENT);
91847e37c4428509524ee576920a98381f3e4872493Nick Pelly        eRet = OMX_ErrorSameState;
91947e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
92047e37c4428509524ee576920a98381f3e4872493Nick Pelly      /* Requesting transition from Idle to WaitForResources */
92147e37c4428509524ee576920a98381f3e4872493Nick Pelly      else if(eState == OMX_StateWaitForResources)
92247e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
92347e37c4428509524ee576920a98381f3e4872493Nick Pelly        DEBUG_PRINT_ERROR("ERROR: OMXCORE-SM: Idle-->WaitForResources\n");
92447e37c4428509524ee576920a98381f3e4872493Nick Pelly        post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\
92547e37c4428509524ee576920a98381f3e4872493Nick Pelly                   OMX_COMPONENT_GENERATE_EVENT);
92647e37c4428509524ee576920a98381f3e4872493Nick Pelly        eRet = OMX_ErrorIncorrectStateTransition;
92747e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
92847e37c4428509524ee576920a98381f3e4872493Nick Pelly      /* Requesting transition from Idle to Pause */
92947e37c4428509524ee576920a98381f3e4872493Nick Pelly      else if(eState == OMX_StatePause)
93047e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
93147e37c4428509524ee576920a98381f3e4872493Nick Pelly        /*To pause the Video core we need to start the driver*/
93247e37c4428509524ee576920a98381f3e4872493Nick Pelly        if( dev_start() )
93347e37c4428509524ee576920a98381f3e4872493Nick Pelly        {
93447e37c4428509524ee576920a98381f3e4872493Nick Pelly          DEBUG_PRINT_ERROR("\nERROR: dev_start() failed in SCP on Idle --> Pause\n");
93547e37c4428509524ee576920a98381f3e4872493Nick Pelly          omx_report_error ();
93647e37c4428509524ee576920a98381f3e4872493Nick Pelly          eRet = OMX_ErrorHardware;
93747e37c4428509524ee576920a98381f3e4872493Nick Pelly        }
93847e37c4428509524ee576920a98381f3e4872493Nick Pelly        else
93947e37c4428509524ee576920a98381f3e4872493Nick Pelly        {
94047e37c4428509524ee576920a98381f3e4872493Nick Pelly          BITMASK_SET(&m_flags,OMX_COMPONENT_PAUSE_PENDING);
941826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev          DEBUG_PRINT_LOW("OMXCORE-SM: Idle-->Pause\n");
94247e37c4428509524ee576920a98381f3e4872493Nick Pelly          bFlag = 0;
94347e37c4428509524ee576920a98381f3e4872493Nick Pelly        }
94447e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
94547e37c4428509524ee576920a98381f3e4872493Nick Pelly      /* Requesting transition from Idle to Invalid */
94647e37c4428509524ee576920a98381f3e4872493Nick Pelly      else if(eState == OMX_StateInvalid)
94747e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
94847e37c4428509524ee576920a98381f3e4872493Nick Pelly        DEBUG_PRINT_ERROR("ERROR: OMXCORE-SM: Idle-->Invalid\n");
94947e37c4428509524ee576920a98381f3e4872493Nick Pelly        post_event(OMX_EventError,eState,OMX_COMPONENT_GENERATE_EVENT);
95047e37c4428509524ee576920a98381f3e4872493Nick Pelly        eRet = OMX_ErrorInvalidState;
95147e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
95247e37c4428509524ee576920a98381f3e4872493Nick Pelly      else
95347e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
95447e37c4428509524ee576920a98381f3e4872493Nick Pelly        DEBUG_PRINT_ERROR("ERROR: OMXCORE-SM: Idle --> %d Not Handled\n",eState);
95547e37c4428509524ee576920a98381f3e4872493Nick Pelly        eRet = OMX_ErrorBadParameter;
95647e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
95747e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
95847e37c4428509524ee576920a98381f3e4872493Nick Pelly
95947e37c4428509524ee576920a98381f3e4872493Nick Pelly    /******************************/
96047e37c4428509524ee576920a98381f3e4872493Nick Pelly    /* Current State is Executing */
96147e37c4428509524ee576920a98381f3e4872493Nick Pelly    /******************************/
96247e37c4428509524ee576920a98381f3e4872493Nick Pelly    else if(m_state == OMX_StateExecuting)
96347e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
96447e37c4428509524ee576920a98381f3e4872493Nick Pelly      /* Requesting transition from Executing to Idle */
96547e37c4428509524ee576920a98381f3e4872493Nick Pelly      if(eState == OMX_StateIdle)
96647e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
96747e37c4428509524ee576920a98381f3e4872493Nick Pelly        /* Since error is None , we will post an event
96847e37c4428509524ee576920a98381f3e4872493Nick Pelly        at the end of this function definition
96947e37c4428509524ee576920a98381f3e4872493Nick Pelly        */
97047e37c4428509524ee576920a98381f3e4872493Nick Pelly        DEBUG_PRINT_LOW("\n OMXCORE-SM: Executing --> Idle \n");
97147e37c4428509524ee576920a98381f3e4872493Nick Pelly        //here this should be Pause-Idle pending and should be cleared when flush is complete and change the state to Idle
97247e37c4428509524ee576920a98381f3e4872493Nick Pelly        BITMASK_SET(&m_flags,OMX_COMPONENT_IDLE_PENDING);
97347e37c4428509524ee576920a98381f3e4872493Nick Pelly        execute_omx_flush(OMX_ALL);
97447e37c4428509524ee576920a98381f3e4872493Nick Pelly        bFlag = 0;
975826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev	dev_stop_done();
97647e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
97747e37c4428509524ee576920a98381f3e4872493Nick Pelly      /* Requesting transition from Executing to Paused */
97847e37c4428509524ee576920a98381f3e4872493Nick Pelly      else if(eState == OMX_StatePause)
97947e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
98047e37c4428509524ee576920a98381f3e4872493Nick Pelly
98147e37c4428509524ee576920a98381f3e4872493Nick Pelly        if(dev_pause())
98247e37c4428509524ee576920a98381f3e4872493Nick Pelly        {
98347e37c4428509524ee576920a98381f3e4872493Nick Pelly          DEBUG_PRINT_ERROR("\nERROR: dev_pause() failed in SCP on Exe --> Pause\n");
98447e37c4428509524ee576920a98381f3e4872493Nick Pelly          post_event(OMX_EventError,OMX_ErrorHardware,\
98547e37c4428509524ee576920a98381f3e4872493Nick Pelly                     OMX_COMPONENT_GENERATE_EVENT);
98647e37c4428509524ee576920a98381f3e4872493Nick Pelly          eRet = OMX_ErrorHardware;
98747e37c4428509524ee576920a98381f3e4872493Nick Pelly        }
98847e37c4428509524ee576920a98381f3e4872493Nick Pelly        else
98947e37c4428509524ee576920a98381f3e4872493Nick Pelly        {
99047e37c4428509524ee576920a98381f3e4872493Nick Pelly          BITMASK_SET(&m_flags,OMX_COMPONENT_PAUSE_PENDING);
991826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev          DEBUG_PRINT_LOW("OMXCORE-SM: Executing-->Pause\n");
99247e37c4428509524ee576920a98381f3e4872493Nick Pelly          bFlag = 0;
99347e37c4428509524ee576920a98381f3e4872493Nick Pelly        }
99447e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
99547e37c4428509524ee576920a98381f3e4872493Nick Pelly      /* Requesting transition from Executing to Loaded */
99647e37c4428509524ee576920a98381f3e4872493Nick Pelly      else if(eState == OMX_StateLoaded)
99747e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
99847e37c4428509524ee576920a98381f3e4872493Nick Pelly        DEBUG_PRINT_ERROR("\nERROR: OMXCORE-SM: Executing --> Loaded \n");
99947e37c4428509524ee576920a98381f3e4872493Nick Pelly        post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\
100047e37c4428509524ee576920a98381f3e4872493Nick Pelly                   OMX_COMPONENT_GENERATE_EVENT);
100147e37c4428509524ee576920a98381f3e4872493Nick Pelly        eRet = OMX_ErrorIncorrectStateTransition;
100247e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
100347e37c4428509524ee576920a98381f3e4872493Nick Pelly      /* Requesting transition from Executing to WaitForResources */
100447e37c4428509524ee576920a98381f3e4872493Nick Pelly      else if(eState == OMX_StateWaitForResources)
100547e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
100647e37c4428509524ee576920a98381f3e4872493Nick Pelly        DEBUG_PRINT_ERROR("\nERROR: OMXCORE-SM: Executing --> WaitForResources \n");
100747e37c4428509524ee576920a98381f3e4872493Nick Pelly        post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\
100847e37c4428509524ee576920a98381f3e4872493Nick Pelly                   OMX_COMPONENT_GENERATE_EVENT);
100947e37c4428509524ee576920a98381f3e4872493Nick Pelly        eRet = OMX_ErrorIncorrectStateTransition;
101047e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
101147e37c4428509524ee576920a98381f3e4872493Nick Pelly      /* Requesting transition from Executing to Executing */
101247e37c4428509524ee576920a98381f3e4872493Nick Pelly      else if(eState == OMX_StateExecuting)
101347e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
101447e37c4428509524ee576920a98381f3e4872493Nick Pelly        DEBUG_PRINT_ERROR("\nERROR: OMXCORE-SM: Executing --> Executing \n");
101547e37c4428509524ee576920a98381f3e4872493Nick Pelly        post_event(OMX_EventError,OMX_ErrorSameState,\
101647e37c4428509524ee576920a98381f3e4872493Nick Pelly                   OMX_COMPONENT_GENERATE_EVENT);
101747e37c4428509524ee576920a98381f3e4872493Nick Pelly        eRet = OMX_ErrorSameState;
101847e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
101947e37c4428509524ee576920a98381f3e4872493Nick Pelly      /* Requesting transition from Executing to Invalid */
102047e37c4428509524ee576920a98381f3e4872493Nick Pelly      else if(eState == OMX_StateInvalid)
102147e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
102247e37c4428509524ee576920a98381f3e4872493Nick Pelly        DEBUG_PRINT_ERROR("\nERROR: OMXCORE-SM: Executing --> Invalid \n");
102347e37c4428509524ee576920a98381f3e4872493Nick Pelly        post_event(OMX_EventError,eState,OMX_COMPONENT_GENERATE_EVENT);
102447e37c4428509524ee576920a98381f3e4872493Nick Pelly        eRet = OMX_ErrorInvalidState;
102547e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
102647e37c4428509524ee576920a98381f3e4872493Nick Pelly      else
102747e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
102847e37c4428509524ee576920a98381f3e4872493Nick Pelly        DEBUG_PRINT_ERROR("ERROR: OMXCORE-SM: Executing --> %d Not Handled\n",eState);
102947e37c4428509524ee576920a98381f3e4872493Nick Pelly        eRet = OMX_ErrorBadParameter;
103047e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
103147e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
103247e37c4428509524ee576920a98381f3e4872493Nick Pelly    /***************************/
103347e37c4428509524ee576920a98381f3e4872493Nick Pelly    /* Current State is Pause  */
103447e37c4428509524ee576920a98381f3e4872493Nick Pelly    /***************************/
103547e37c4428509524ee576920a98381f3e4872493Nick Pelly    else if(m_state == OMX_StatePause)
103647e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
103747e37c4428509524ee576920a98381f3e4872493Nick Pelly      /* Requesting transition from Pause to Executing */
103847e37c4428509524ee576920a98381f3e4872493Nick Pelly      if(eState == OMX_StateExecuting)
103947e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
104047e37c4428509524ee576920a98381f3e4872493Nick Pelly        DEBUG_PRINT_LOW("\n Pause --> Executing \n");
104147e37c4428509524ee576920a98381f3e4872493Nick Pelly        if( dev_resume() )
104247e37c4428509524ee576920a98381f3e4872493Nick Pelly        {
104347e37c4428509524ee576920a98381f3e4872493Nick Pelly          post_event(OMX_EventError,OMX_ErrorHardware,\
104447e37c4428509524ee576920a98381f3e4872493Nick Pelly                     OMX_COMPONENT_GENERATE_EVENT);
104547e37c4428509524ee576920a98381f3e4872493Nick Pelly          eRet = OMX_ErrorHardware;
104647e37c4428509524ee576920a98381f3e4872493Nick Pelly        }
104747e37c4428509524ee576920a98381f3e4872493Nick Pelly        else
104847e37c4428509524ee576920a98381f3e4872493Nick Pelly        {
104947e37c4428509524ee576920a98381f3e4872493Nick Pelly          BITMASK_SET(&m_flags,OMX_COMPONENT_EXECUTE_PENDING);
1050826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev          DEBUG_PRINT_LOW("OMXCORE-SM: Pause-->Executing\n");
1051826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev          post_event (NULL, NULL, OMX_COMPONENT_GENERATE_RESUME_DONE);
105247e37c4428509524ee576920a98381f3e4872493Nick Pelly          bFlag = 0;
105347e37c4428509524ee576920a98381f3e4872493Nick Pelly        }
105447e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
105547e37c4428509524ee576920a98381f3e4872493Nick Pelly      /* Requesting transition from Pause to Idle */
105647e37c4428509524ee576920a98381f3e4872493Nick Pelly      else if(eState == OMX_StateIdle)
105747e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
105847e37c4428509524ee576920a98381f3e4872493Nick Pelly        /* Since error is None , we will post an event
105947e37c4428509524ee576920a98381f3e4872493Nick Pelly        at the end of this function definition */
106047e37c4428509524ee576920a98381f3e4872493Nick Pelly        DEBUG_PRINT_LOW("\n Pause --> Idle \n");
106147e37c4428509524ee576920a98381f3e4872493Nick Pelly        BITMASK_SET(&m_flags,OMX_COMPONENT_IDLE_PENDING);
106247e37c4428509524ee576920a98381f3e4872493Nick Pelly        execute_omx_flush(OMX_ALL);
106347e37c4428509524ee576920a98381f3e4872493Nick Pelly        bFlag = 0;
106447e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
106547e37c4428509524ee576920a98381f3e4872493Nick Pelly      /* Requesting transition from Pause to loaded */
106647e37c4428509524ee576920a98381f3e4872493Nick Pelly      else if(eState == OMX_StateLoaded)
106747e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
106847e37c4428509524ee576920a98381f3e4872493Nick Pelly        DEBUG_PRINT_ERROR("\nERROR: Pause --> loaded \n");
106947e37c4428509524ee576920a98381f3e4872493Nick Pelly        post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\
107047e37c4428509524ee576920a98381f3e4872493Nick Pelly                   OMX_COMPONENT_GENERATE_EVENT);
107147e37c4428509524ee576920a98381f3e4872493Nick Pelly        eRet = OMX_ErrorIncorrectStateTransition;
107247e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
107347e37c4428509524ee576920a98381f3e4872493Nick Pelly      /* Requesting transition from Pause to WaitForResources */
107447e37c4428509524ee576920a98381f3e4872493Nick Pelly      else if(eState == OMX_StateWaitForResources)
107547e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
107647e37c4428509524ee576920a98381f3e4872493Nick Pelly        DEBUG_PRINT_ERROR("\nERROR: Pause --> WaitForResources \n");
107747e37c4428509524ee576920a98381f3e4872493Nick Pelly        post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\
107847e37c4428509524ee576920a98381f3e4872493Nick Pelly                   OMX_COMPONENT_GENERATE_EVENT);
107947e37c4428509524ee576920a98381f3e4872493Nick Pelly        eRet = OMX_ErrorIncorrectStateTransition;
108047e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
108147e37c4428509524ee576920a98381f3e4872493Nick Pelly      /* Requesting transition from Pause to Pause */
108247e37c4428509524ee576920a98381f3e4872493Nick Pelly      else if(eState == OMX_StatePause)
108347e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
108447e37c4428509524ee576920a98381f3e4872493Nick Pelly        DEBUG_PRINT_ERROR("\nERROR: Pause --> Pause \n");
108547e37c4428509524ee576920a98381f3e4872493Nick Pelly        post_event(OMX_EventError,OMX_ErrorSameState,\
108647e37c4428509524ee576920a98381f3e4872493Nick Pelly                   OMX_COMPONENT_GENERATE_EVENT);
108747e37c4428509524ee576920a98381f3e4872493Nick Pelly        eRet = OMX_ErrorSameState;
108847e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
108947e37c4428509524ee576920a98381f3e4872493Nick Pelly      /* Requesting transition from Pause to Invalid */
109047e37c4428509524ee576920a98381f3e4872493Nick Pelly      else if(eState == OMX_StateInvalid)
109147e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
109247e37c4428509524ee576920a98381f3e4872493Nick Pelly        DEBUG_PRINT_ERROR("\nERROR: Pause --> Invalid \n");
109347e37c4428509524ee576920a98381f3e4872493Nick Pelly        post_event(OMX_EventError,eState,OMX_COMPONENT_GENERATE_EVENT);
109447e37c4428509524ee576920a98381f3e4872493Nick Pelly        eRet = OMX_ErrorInvalidState;
109547e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
109647e37c4428509524ee576920a98381f3e4872493Nick Pelly      else
109747e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
109847e37c4428509524ee576920a98381f3e4872493Nick Pelly        DEBUG_PRINT_ERROR("ERROR: OMXCORE-SM: Paused --> %d Not Handled\n",eState);
109947e37c4428509524ee576920a98381f3e4872493Nick Pelly        eRet = OMX_ErrorBadParameter;
110047e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
110147e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
110247e37c4428509524ee576920a98381f3e4872493Nick Pelly    /***************************/
110347e37c4428509524ee576920a98381f3e4872493Nick Pelly    /* Current State is WaitForResources  */
110447e37c4428509524ee576920a98381f3e4872493Nick Pelly    /***************************/
110547e37c4428509524ee576920a98381f3e4872493Nick Pelly    else if(m_state == OMX_StateWaitForResources)
110647e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
110747e37c4428509524ee576920a98381f3e4872493Nick Pelly      /* Requesting transition from WaitForResources to Loaded */
110847e37c4428509524ee576920a98381f3e4872493Nick Pelly      if(eState == OMX_StateLoaded)
110947e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
111047e37c4428509524ee576920a98381f3e4872493Nick Pelly        /* Since error is None , we will post an event
111147e37c4428509524ee576920a98381f3e4872493Nick Pelly        at the end of this function definition */
111247e37c4428509524ee576920a98381f3e4872493Nick Pelly        DEBUG_PRINT_LOW("OMXCORE-SM: WaitForResources-->Loaded\n");
111347e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
111447e37c4428509524ee576920a98381f3e4872493Nick Pelly      /* Requesting transition from WaitForResources to WaitForResources */
111547e37c4428509524ee576920a98381f3e4872493Nick Pelly      else if(eState == OMX_StateWaitForResources)
111647e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
111747e37c4428509524ee576920a98381f3e4872493Nick Pelly        DEBUG_PRINT_ERROR("ERROR: OMXCORE-SM: WaitForResources-->WaitForResources\n");
111847e37c4428509524ee576920a98381f3e4872493Nick Pelly        post_event(OMX_EventError,OMX_ErrorSameState,
111947e37c4428509524ee576920a98381f3e4872493Nick Pelly                   OMX_COMPONENT_GENERATE_EVENT);
112047e37c4428509524ee576920a98381f3e4872493Nick Pelly        eRet = OMX_ErrorSameState;
112147e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
112247e37c4428509524ee576920a98381f3e4872493Nick Pelly      /* Requesting transition from WaitForResources to Executing */
112347e37c4428509524ee576920a98381f3e4872493Nick Pelly      else if(eState == OMX_StateExecuting)
112447e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
112547e37c4428509524ee576920a98381f3e4872493Nick Pelly        DEBUG_PRINT_ERROR("ERROR: OMXCORE-SM: WaitForResources-->Executing\n");
112647e37c4428509524ee576920a98381f3e4872493Nick Pelly        post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\
112747e37c4428509524ee576920a98381f3e4872493Nick Pelly                   OMX_COMPONENT_GENERATE_EVENT);
112847e37c4428509524ee576920a98381f3e4872493Nick Pelly        eRet = OMX_ErrorIncorrectStateTransition;
112947e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
113047e37c4428509524ee576920a98381f3e4872493Nick Pelly      /* Requesting transition from WaitForResources to Pause */
113147e37c4428509524ee576920a98381f3e4872493Nick Pelly      else if(eState == OMX_StatePause)
113247e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
113347e37c4428509524ee576920a98381f3e4872493Nick Pelly        DEBUG_PRINT_ERROR("ERROR: OMXCORE-SM: WaitForResources-->Pause\n");
113447e37c4428509524ee576920a98381f3e4872493Nick Pelly        post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\
113547e37c4428509524ee576920a98381f3e4872493Nick Pelly                   OMX_COMPONENT_GENERATE_EVENT);
113647e37c4428509524ee576920a98381f3e4872493Nick Pelly        eRet = OMX_ErrorIncorrectStateTransition;
113747e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
113847e37c4428509524ee576920a98381f3e4872493Nick Pelly      /* Requesting transition from WaitForResources to Invalid */
113947e37c4428509524ee576920a98381f3e4872493Nick Pelly      else if(eState == OMX_StateInvalid)
114047e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
114147e37c4428509524ee576920a98381f3e4872493Nick Pelly        DEBUG_PRINT_ERROR("ERROR: OMXCORE-SM: WaitForResources-->Invalid\n");
114247e37c4428509524ee576920a98381f3e4872493Nick Pelly        post_event(OMX_EventError,eState,OMX_COMPONENT_GENERATE_EVENT);
114347e37c4428509524ee576920a98381f3e4872493Nick Pelly        eRet = OMX_ErrorInvalidState;
114447e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
114547e37c4428509524ee576920a98381f3e4872493Nick Pelly      /* Requesting transition from WaitForResources to Loaded -
114647e37c4428509524ee576920a98381f3e4872493Nick Pelly      is NOT tested by Khronos TS */
114747e37c4428509524ee576920a98381f3e4872493Nick Pelly
114847e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
114947e37c4428509524ee576920a98381f3e4872493Nick Pelly    else
115047e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
115147e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_ERROR("ERROR: OMXCORE-SM: %d --> %d(Not Handled)\n",m_state,eState);
115247e37c4428509524ee576920a98381f3e4872493Nick Pelly      eRet = OMX_ErrorBadParameter;
115347e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
115447e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
115547e37c4428509524ee576920a98381f3e4872493Nick Pelly  /********************************/
115647e37c4428509524ee576920a98381f3e4872493Nick Pelly  /* Current State is Invalid */
115747e37c4428509524ee576920a98381f3e4872493Nick Pelly  /*******************************/
115847e37c4428509524ee576920a98381f3e4872493Nick Pelly  else if(m_state == OMX_StateInvalid)
115947e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
116047e37c4428509524ee576920a98381f3e4872493Nick Pelly    /* State Transition from Inavlid to any state */
116147e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(eState == (OMX_StateLoaded || OMX_StateWaitForResources
116247e37c4428509524ee576920a98381f3e4872493Nick Pelly                  || OMX_StateIdle || OMX_StateExecuting
116347e37c4428509524ee576920a98381f3e4872493Nick Pelly                  || OMX_StatePause || OMX_StateInvalid))
116447e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
116547e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_ERROR("ERROR: OMXCORE-SM: Invalid -->Loaded\n");
116647e37c4428509524ee576920a98381f3e4872493Nick Pelly      post_event(OMX_EventError,OMX_ErrorInvalidState,\
116747e37c4428509524ee576920a98381f3e4872493Nick Pelly                 OMX_COMPONENT_GENERATE_EVENT);
116847e37c4428509524ee576920a98381f3e4872493Nick Pelly      eRet = OMX_ErrorInvalidState;
116947e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
117047e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
117147e37c4428509524ee576920a98381f3e4872493Nick Pelly  else if(cmd == OMX_CommandFlush)
117247e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
117347e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(0 == param1 || OMX_ALL == param1)
117447e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
117547e37c4428509524ee576920a98381f3e4872493Nick Pelly      BITMASK_SET(&m_flags, OMX_COMPONENT_INPUT_FLUSH_PENDING);
117647e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
117747e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(1 == param1 || OMX_ALL == param1)
117847e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
117947e37c4428509524ee576920a98381f3e4872493Nick Pelly      //generate output flush event only.
118047e37c4428509524ee576920a98381f3e4872493Nick Pelly      BITMASK_SET(&m_flags, OMX_COMPONENT_OUTPUT_FLUSH_PENDING);
118147e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
118247e37c4428509524ee576920a98381f3e4872493Nick Pelly
118347e37c4428509524ee576920a98381f3e4872493Nick Pelly    execute_omx_flush(param1);
118447e37c4428509524ee576920a98381f3e4872493Nick Pelly    bFlag = 0;
118547e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
118647e37c4428509524ee576920a98381f3e4872493Nick Pelly  else if( cmd == OMX_CommandPortEnable)
118747e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
118847e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(param1 == PORT_INDEX_IN || param1 == OMX_ALL)
118947e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
119047e37c4428509524ee576920a98381f3e4872493Nick Pelly      m_sInPortDef.bEnabled = OMX_TRUE;
119147e37c4428509524ee576920a98381f3e4872493Nick Pelly
119247e37c4428509524ee576920a98381f3e4872493Nick Pelly      if( (m_state == OMX_StateLoaded &&
119347e37c4428509524ee576920a98381f3e4872493Nick Pelly           !BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING))
119447e37c4428509524ee576920a98381f3e4872493Nick Pelly          || allocate_input_done())
119547e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
119647e37c4428509524ee576920a98381f3e4872493Nick Pelly        post_event(OMX_CommandPortEnable,PORT_INDEX_IN,
119747e37c4428509524ee576920a98381f3e4872493Nick Pelly                   OMX_COMPONENT_GENERATE_EVENT);
119847e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
119947e37c4428509524ee576920a98381f3e4872493Nick Pelly      else
120047e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
120147e37c4428509524ee576920a98381f3e4872493Nick Pelly        DEBUG_PRINT_LOW("OMXCORE-SM: Disabled-->Enabled Pending\n");
120247e37c4428509524ee576920a98381f3e4872493Nick Pelly        BITMASK_SET(&m_flags, OMX_COMPONENT_INPUT_ENABLE_PENDING);
120347e37c4428509524ee576920a98381f3e4872493Nick Pelly        // Skip the event notification
120447e37c4428509524ee576920a98381f3e4872493Nick Pelly        bFlag = 0;
120547e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
120647e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
120747e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(param1 == PORT_INDEX_OUT || param1 == OMX_ALL)
120847e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
120947e37c4428509524ee576920a98381f3e4872493Nick Pelly      m_sOutPortDef.bEnabled = OMX_TRUE;
121047e37c4428509524ee576920a98381f3e4872493Nick Pelly
121147e37c4428509524ee576920a98381f3e4872493Nick Pelly      if( (m_state == OMX_StateLoaded &&
121247e37c4428509524ee576920a98381f3e4872493Nick Pelly           !BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING))
121347e37c4428509524ee576920a98381f3e4872493Nick Pelly          || (allocate_output_done()))
121447e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
121547e37c4428509524ee576920a98381f3e4872493Nick Pelly        post_event(OMX_CommandPortEnable,PORT_INDEX_OUT,
121647e37c4428509524ee576920a98381f3e4872493Nick Pelly                   OMX_COMPONENT_GENERATE_EVENT);
121747e37c4428509524ee576920a98381f3e4872493Nick Pelly
121847e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
121947e37c4428509524ee576920a98381f3e4872493Nick Pelly      else
122047e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
122147e37c4428509524ee576920a98381f3e4872493Nick Pelly        DEBUG_PRINT_LOW("OMXCORE-SM: Disabled-->Enabled Pending\n");
122247e37c4428509524ee576920a98381f3e4872493Nick Pelly        BITMASK_SET(&m_flags, OMX_COMPONENT_OUTPUT_ENABLE_PENDING);
122347e37c4428509524ee576920a98381f3e4872493Nick Pelly        // Skip the event notification
122447e37c4428509524ee576920a98381f3e4872493Nick Pelly        bFlag = 0;
122547e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
122647e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
122747e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
122847e37c4428509524ee576920a98381f3e4872493Nick Pelly  else if(cmd == OMX_CommandPortDisable)
122947e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
123047e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(param1 == PORT_INDEX_IN || param1 == OMX_ALL)
123147e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
123247e37c4428509524ee576920a98381f3e4872493Nick Pelly      m_sInPortDef.bEnabled = OMX_FALSE;
123347e37c4428509524ee576920a98381f3e4872493Nick Pelly      if((m_state == OMX_StateLoaded || m_state == OMX_StateIdle)
123447e37c4428509524ee576920a98381f3e4872493Nick Pelly         && release_input_done())
123547e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
123647e37c4428509524ee576920a98381f3e4872493Nick Pelly        post_event(OMX_CommandPortDisable,PORT_INDEX_IN,
123747e37c4428509524ee576920a98381f3e4872493Nick Pelly                   OMX_COMPONENT_GENERATE_EVENT);
123847e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
123947e37c4428509524ee576920a98381f3e4872493Nick Pelly      else
124047e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
124147e37c4428509524ee576920a98381f3e4872493Nick Pelly        BITMASK_SET(&m_flags, OMX_COMPONENT_INPUT_DISABLE_PENDING);
124247e37c4428509524ee576920a98381f3e4872493Nick Pelly        if(m_state == OMX_StatePause ||m_state == OMX_StateExecuting)
124347e37c4428509524ee576920a98381f3e4872493Nick Pelly        {
124447e37c4428509524ee576920a98381f3e4872493Nick Pelly          execute_omx_flush(PORT_INDEX_IN);
124547e37c4428509524ee576920a98381f3e4872493Nick Pelly        }
124647e37c4428509524ee576920a98381f3e4872493Nick Pelly
124747e37c4428509524ee576920a98381f3e4872493Nick Pelly        // Skip the event notification
124847e37c4428509524ee576920a98381f3e4872493Nick Pelly        bFlag = 0;
124947e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
125047e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
125147e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(param1 == PORT_INDEX_OUT || param1 == OMX_ALL)
125247e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
125347e37c4428509524ee576920a98381f3e4872493Nick Pelly      m_sOutPortDef.bEnabled = OMX_FALSE;
125447e37c4428509524ee576920a98381f3e4872493Nick Pelly
125547e37c4428509524ee576920a98381f3e4872493Nick Pelly      if((m_state == OMX_StateLoaded || m_state == OMX_StateIdle)
125647e37c4428509524ee576920a98381f3e4872493Nick Pelly         && release_output_done())
125747e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
125847e37c4428509524ee576920a98381f3e4872493Nick Pelly        post_event(OMX_CommandPortDisable,PORT_INDEX_OUT,\
125947e37c4428509524ee576920a98381f3e4872493Nick Pelly                   OMX_COMPONENT_GENERATE_EVENT);
126047e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
126147e37c4428509524ee576920a98381f3e4872493Nick Pelly      else
126247e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
126347e37c4428509524ee576920a98381f3e4872493Nick Pelly        BITMASK_SET(&m_flags, OMX_COMPONENT_OUTPUT_DISABLE_PENDING);
126447e37c4428509524ee576920a98381f3e4872493Nick Pelly        if(m_state == OMX_StatePause ||m_state == OMX_StateExecuting)
126547e37c4428509524ee576920a98381f3e4872493Nick Pelly        {
126647e37c4428509524ee576920a98381f3e4872493Nick Pelly          execute_omx_flush(PORT_INDEX_OUT);
126747e37c4428509524ee576920a98381f3e4872493Nick Pelly        }
126847e37c4428509524ee576920a98381f3e4872493Nick Pelly        // Skip the event notification
126947e37c4428509524ee576920a98381f3e4872493Nick Pelly        bFlag = 0;
127047e37c4428509524ee576920a98381f3e4872493Nick Pelly
127147e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
127247e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
127347e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
127447e37c4428509524ee576920a98381f3e4872493Nick Pelly  else
127547e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
127647e37c4428509524ee576920a98381f3e4872493Nick Pelly    DEBUG_PRINT_ERROR("ERROR: Invalid Command received other than StateSet (%d)\n",cmd);
127747e37c4428509524ee576920a98381f3e4872493Nick Pelly    eRet = OMX_ErrorNotImplemented;
127847e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
127947e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(eRet == OMX_ErrorNone && bFlag)
128047e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
128147e37c4428509524ee576920a98381f3e4872493Nick Pelly    post_event(cmd,eState,OMX_COMPONENT_GENERATE_EVENT);
128247e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
128347e37c4428509524ee576920a98381f3e4872493Nick Pelly  sem_post(&m_cmd_lock);
128447e37c4428509524ee576920a98381f3e4872493Nick Pelly  return eRet;
128547e37c4428509524ee576920a98381f3e4872493Nick Pelly}
128647e37c4428509524ee576920a98381f3e4872493Nick Pelly
128747e37c4428509524ee576920a98381f3e4872493Nick Pelly/* ======================================================================
128847e37c4428509524ee576920a98381f3e4872493Nick PellyFUNCTION
128947e37c4428509524ee576920a98381f3e4872493Nick Pelly  omx_venc::ExecuteOmxFlush
129047e37c4428509524ee576920a98381f3e4872493Nick Pelly
129147e37c4428509524ee576920a98381f3e4872493Nick PellyDESCRIPTION
129247e37c4428509524ee576920a98381f3e4872493Nick Pelly  Executes the OMX flush.
129347e37c4428509524ee576920a98381f3e4872493Nick Pelly
129447e37c4428509524ee576920a98381f3e4872493Nick PellyPARAMETERS
129547e37c4428509524ee576920a98381f3e4872493Nick Pelly  flushtype - input flush(1)/output flush(0)/ both.
129647e37c4428509524ee576920a98381f3e4872493Nick Pelly
129747e37c4428509524ee576920a98381f3e4872493Nick PellyRETURN VALUE
129847e37c4428509524ee576920a98381f3e4872493Nick Pelly  true/false
129947e37c4428509524ee576920a98381f3e4872493Nick Pelly
130047e37c4428509524ee576920a98381f3e4872493Nick Pelly========================================================================== */
130147e37c4428509524ee576920a98381f3e4872493Nick Pellybool omx_video::execute_omx_flush(OMX_U32 flushType)
130247e37c4428509524ee576920a98381f3e4872493Nick Pelly{
130347e37c4428509524ee576920a98381f3e4872493Nick Pelly  bool bRet = false;
130447e37c4428509524ee576920a98381f3e4872493Nick Pelly  DEBUG_PRINT_LOW("\n execute_omx_flush -  %d\n", flushType);
130547e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(flushType == 0 || flushType == OMX_ALL)
130647e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
130747e37c4428509524ee576920a98381f3e4872493Nick Pelly    input_flush_progress = true;
130847e37c4428509524ee576920a98381f3e4872493Nick Pelly    //flush input only
130947e37c4428509524ee576920a98381f3e4872493Nick Pelly    bRet = execute_input_flush();
131047e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
131147e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(flushType == 1 || flushType == OMX_ALL)
131247e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
131347e37c4428509524ee576920a98381f3e4872493Nick Pelly    //flush output only
131447e37c4428509524ee576920a98381f3e4872493Nick Pelly    output_flush_progress = true;
131547e37c4428509524ee576920a98381f3e4872493Nick Pelly    bRet = execute_output_flush();
131647e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
131747e37c4428509524ee576920a98381f3e4872493Nick Pelly  return bRet;
131847e37c4428509524ee576920a98381f3e4872493Nick Pelly}
131947e37c4428509524ee576920a98381f3e4872493Nick Pelly/*=========================================================================
132047e37c4428509524ee576920a98381f3e4872493Nick PellyFUNCTION : execute_output_flush
132147e37c4428509524ee576920a98381f3e4872493Nick Pelly
132247e37c4428509524ee576920a98381f3e4872493Nick PellyDESCRIPTION
132347e37c4428509524ee576920a98381f3e4872493Nick Pelly  Executes the OMX flush at OUTPUT PORT.
132447e37c4428509524ee576920a98381f3e4872493Nick Pelly
132547e37c4428509524ee576920a98381f3e4872493Nick PellyPARAMETERS
132647e37c4428509524ee576920a98381f3e4872493Nick Pelly  None.
132747e37c4428509524ee576920a98381f3e4872493Nick Pelly
132847e37c4428509524ee576920a98381f3e4872493Nick PellyRETURN VALUE
132947e37c4428509524ee576920a98381f3e4872493Nick Pelly  true/false
133047e37c4428509524ee576920a98381f3e4872493Nick Pelly==========================================================================*/
133147e37c4428509524ee576920a98381f3e4872493Nick Pellybool omx_video::execute_output_flush(void)
133247e37c4428509524ee576920a98381f3e4872493Nick Pelly{
133347e37c4428509524ee576920a98381f3e4872493Nick Pelly  unsigned      p1 = 0; // Parameter - 1
133447e37c4428509524ee576920a98381f3e4872493Nick Pelly  unsigned      p2 = 0; // Parameter - 2
133547e37c4428509524ee576920a98381f3e4872493Nick Pelly  unsigned      ident = 0;
133647e37c4428509524ee576920a98381f3e4872493Nick Pelly  bool bRet = true;
133747e37c4428509524ee576920a98381f3e4872493Nick Pelly
133847e37c4428509524ee576920a98381f3e4872493Nick Pelly  /*Generate FBD for all Buffers in the FTBq*/
133947e37c4428509524ee576920a98381f3e4872493Nick Pelly  DEBUG_PRINT_LOW("\n execute_output_flush\n");
134047e37c4428509524ee576920a98381f3e4872493Nick Pelly  pthread_mutex_lock(&m_lock);
134147e37c4428509524ee576920a98381f3e4872493Nick Pelly  while(m_ftb_q.m_size)
134247e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
134347e37c4428509524ee576920a98381f3e4872493Nick Pelly    m_ftb_q.pop_entry(&p1,&p2,&ident);
134447e37c4428509524ee576920a98381f3e4872493Nick Pelly
134547e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(ident == OMX_COMPONENT_GENERATE_FTB )
134647e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
134747e37c4428509524ee576920a98381f3e4872493Nick Pelly      pending_output_buffers++;
134847e37c4428509524ee576920a98381f3e4872493Nick Pelly      fill_buffer_done(&m_cmp,(OMX_BUFFERHEADERTYPE *)p2);
134947e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
135047e37c4428509524ee576920a98381f3e4872493Nick Pelly    else if(ident == OMX_COMPONENT_GENERATE_FBD)
135147e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
135247e37c4428509524ee576920a98381f3e4872493Nick Pelly      fill_buffer_done(&m_cmp,(OMX_BUFFERHEADERTYPE *)p1);
135347e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
135447e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
135547e37c4428509524ee576920a98381f3e4872493Nick Pelly
135647e37c4428509524ee576920a98381f3e4872493Nick Pelly  pthread_mutex_unlock(&m_lock);
135747e37c4428509524ee576920a98381f3e4872493Nick Pelly  /*Check if there are buffers with the Driver*/
135847e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(dev_flush(PORT_INDEX_OUT))
135947e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
136047e37c4428509524ee576920a98381f3e4872493Nick Pelly    DEBUG_PRINT_ERROR("\nERROR: o/p dev_flush() Failed");
136147e37c4428509524ee576920a98381f3e4872493Nick Pelly    return false;
136247e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
136347e37c4428509524ee576920a98381f3e4872493Nick Pelly
136447e37c4428509524ee576920a98381f3e4872493Nick Pelly  return bRet;
136547e37c4428509524ee576920a98381f3e4872493Nick Pelly}
136647e37c4428509524ee576920a98381f3e4872493Nick Pelly/*=========================================================================
136747e37c4428509524ee576920a98381f3e4872493Nick PellyFUNCTION : execute_input_flush
136847e37c4428509524ee576920a98381f3e4872493Nick Pelly
136947e37c4428509524ee576920a98381f3e4872493Nick PellyDESCRIPTION
137047e37c4428509524ee576920a98381f3e4872493Nick Pelly  Executes the OMX flush at INPUT PORT.
137147e37c4428509524ee576920a98381f3e4872493Nick Pelly
137247e37c4428509524ee576920a98381f3e4872493Nick PellyPARAMETERS
137347e37c4428509524ee576920a98381f3e4872493Nick Pelly  None.
137447e37c4428509524ee576920a98381f3e4872493Nick Pelly
137547e37c4428509524ee576920a98381f3e4872493Nick PellyRETURN VALUE
137647e37c4428509524ee576920a98381f3e4872493Nick Pelly  true/false
137747e37c4428509524ee576920a98381f3e4872493Nick Pelly==========================================================================*/
137847e37c4428509524ee576920a98381f3e4872493Nick Pellybool omx_video::execute_input_flush(void)
137947e37c4428509524ee576920a98381f3e4872493Nick Pelly{
138047e37c4428509524ee576920a98381f3e4872493Nick Pelly  unsigned      p1 = 0; // Parameter - 1
138147e37c4428509524ee576920a98381f3e4872493Nick Pelly  unsigned      p2 = 0; // Parameter - 2
138247e37c4428509524ee576920a98381f3e4872493Nick Pelly  unsigned      ident = 0;
138347e37c4428509524ee576920a98381f3e4872493Nick Pelly  bool bRet = true;
138447e37c4428509524ee576920a98381f3e4872493Nick Pelly
138547e37c4428509524ee576920a98381f3e4872493Nick Pelly  /*Generate EBD for all Buffers in the ETBq*/
138647e37c4428509524ee576920a98381f3e4872493Nick Pelly  DEBUG_PRINT_LOW("\n execute_input_flush\n");
138747e37c4428509524ee576920a98381f3e4872493Nick Pelly
138847e37c4428509524ee576920a98381f3e4872493Nick Pelly  pthread_mutex_lock(&m_lock);
138947e37c4428509524ee576920a98381f3e4872493Nick Pelly  while(m_etb_q.m_size)
139047e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
139147e37c4428509524ee576920a98381f3e4872493Nick Pelly    m_etb_q.pop_entry(&p1,&p2,&ident);
139247e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(ident == OMX_COMPONENT_GENERATE_ETB)
139347e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
139447e37c4428509524ee576920a98381f3e4872493Nick Pelly      pending_input_buffers++;
139547e37c4428509524ee576920a98381f3e4872493Nick Pelly      empty_buffer_done(&m_cmp,(OMX_BUFFERHEADERTYPE *)p2);
139647e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
139747e37c4428509524ee576920a98381f3e4872493Nick Pelly    else if(ident == OMX_COMPONENT_GENERATE_EBD)
139847e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
139947e37c4428509524ee576920a98381f3e4872493Nick Pelly      empty_buffer_done(&m_cmp,(OMX_BUFFERHEADERTYPE *)p1);
140047e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
14017eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    else if(ident == OMX_COMPONENT_GENERATE_ETB_OPQ)
14027eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    {
14037eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      m_pCallbacks.EmptyBufferDone(&m_cmp,m_app_data,(OMX_BUFFERHEADERTYPE *)p2);
14047eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    }
14057eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  }
14067eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  if(mUseProxyColorFormat) {
14077eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    if(psource_frame) {
14087eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      m_pCallbacks.EmptyBufferDone(&m_cmp,m_app_data,psource_frame);
14097eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      psource_frame = NULL;
14107eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    }
14117eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    while(m_opq_meta_q.m_size) {
14127eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      unsigned p1,p2,id;
14137eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      m_opq_meta_q.pop_entry(&p1,&p2,&id);
14147eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      m_pCallbacks.EmptyBufferDone(&m_cmp,m_app_data,
14157eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George         (OMX_BUFFERHEADERTYPE  *)p1);
14167eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    }
14177eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    if(pdest_frame){
14187eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      m_opq_pmem_q.insert_entry((unsigned int)pdest_frame,0,0);
14197eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      pdest_frame = NULL;
14207eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    }
142147e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
142247e37c4428509524ee576920a98381f3e4872493Nick Pelly  pthread_mutex_unlock(&m_lock);
142347e37c4428509524ee576920a98381f3e4872493Nick Pelly  /*Check if there are buffers with the Driver*/
142447e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(dev_flush(PORT_INDEX_IN))
142547e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
142647e37c4428509524ee576920a98381f3e4872493Nick Pelly    DEBUG_PRINT_ERROR("\nERROR: i/p dev_flush() Failed");
142747e37c4428509524ee576920a98381f3e4872493Nick Pelly    return false;
142847e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
142947e37c4428509524ee576920a98381f3e4872493Nick Pelly
143047e37c4428509524ee576920a98381f3e4872493Nick Pelly  return bRet;
143147e37c4428509524ee576920a98381f3e4872493Nick Pelly}
143247e37c4428509524ee576920a98381f3e4872493Nick Pelly
143347e37c4428509524ee576920a98381f3e4872493Nick Pelly
143447e37c4428509524ee576920a98381f3e4872493Nick Pelly/* ======================================================================
143547e37c4428509524ee576920a98381f3e4872493Nick PellyFUNCTION
143647e37c4428509524ee576920a98381f3e4872493Nick Pelly  omx_venc::SendCommandEvent
143747e37c4428509524ee576920a98381f3e4872493Nick Pelly
143847e37c4428509524ee576920a98381f3e4872493Nick PellyDESCRIPTION
143947e37c4428509524ee576920a98381f3e4872493Nick Pelly  Send the event to decoder pipe.  This is needed to generate the callbacks
144047e37c4428509524ee576920a98381f3e4872493Nick Pelly  in decoder thread context.
144147e37c4428509524ee576920a98381f3e4872493Nick Pelly
144247e37c4428509524ee576920a98381f3e4872493Nick PellyPARAMETERS
144347e37c4428509524ee576920a98381f3e4872493Nick Pelly  None.
144447e37c4428509524ee576920a98381f3e4872493Nick Pelly
144547e37c4428509524ee576920a98381f3e4872493Nick PellyRETURN VALUE
144647e37c4428509524ee576920a98381f3e4872493Nick Pelly  true/false
144747e37c4428509524ee576920a98381f3e4872493Nick Pelly
144847e37c4428509524ee576920a98381f3e4872493Nick Pelly========================================================================== */
144947e37c4428509524ee576920a98381f3e4872493Nick Pellybool omx_video::post_event(unsigned int p1,
145047e37c4428509524ee576920a98381f3e4872493Nick Pelly                           unsigned int p2,
145147e37c4428509524ee576920a98381f3e4872493Nick Pelly                           unsigned int id)
145247e37c4428509524ee576920a98381f3e4872493Nick Pelly{
145347e37c4428509524ee576920a98381f3e4872493Nick Pelly  bool bRet      =                      false;
145447e37c4428509524ee576920a98381f3e4872493Nick Pelly
145547e37c4428509524ee576920a98381f3e4872493Nick Pelly
145647e37c4428509524ee576920a98381f3e4872493Nick Pelly  pthread_mutex_lock(&m_lock);
145747e37c4428509524ee576920a98381f3e4872493Nick Pelly
145847e37c4428509524ee576920a98381f3e4872493Nick Pelly  if( id == OMX_COMPONENT_GENERATE_FTB || \
145947e37c4428509524ee576920a98381f3e4872493Nick Pelly      (id == OMX_COMPONENT_GENERATE_FRAME_DONE))
146047e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
146147e37c4428509524ee576920a98381f3e4872493Nick Pelly    m_ftb_q.insert_entry(p1,p2,id);
146247e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
14637eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  else if((id == m_input_msg_id) \
146447e37c4428509524ee576920a98381f3e4872493Nick Pelly          || (id == OMX_COMPONENT_GENERATE_EBD))
146547e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
146647e37c4428509524ee576920a98381f3e4872493Nick Pelly    m_etb_q.insert_entry(p1,p2,id);
146747e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
146847e37c4428509524ee576920a98381f3e4872493Nick Pelly  else
146947e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
147047e37c4428509524ee576920a98381f3e4872493Nick Pelly    m_cmd_q.insert_entry(p1,p2,id);
147147e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
147247e37c4428509524ee576920a98381f3e4872493Nick Pelly
147347e37c4428509524ee576920a98381f3e4872493Nick Pelly  bRet = true;
147447e37c4428509524ee576920a98381f3e4872493Nick Pelly  DEBUG_PRINT_LOW("\n Value of this pointer in post_event %p",this);
147547e37c4428509524ee576920a98381f3e4872493Nick Pelly  post_message(this, id);
147647e37c4428509524ee576920a98381f3e4872493Nick Pelly  pthread_mutex_unlock(&m_lock);
147747e37c4428509524ee576920a98381f3e4872493Nick Pelly
147847e37c4428509524ee576920a98381f3e4872493Nick Pelly  return bRet;
147947e37c4428509524ee576920a98381f3e4872493Nick Pelly}
148047e37c4428509524ee576920a98381f3e4872493Nick Pelly
148147e37c4428509524ee576920a98381f3e4872493Nick Pelly/* ======================================================================
148247e37c4428509524ee576920a98381f3e4872493Nick PellyFUNCTION
148347e37c4428509524ee576920a98381f3e4872493Nick Pelly  omx_venc::GetParameter
148447e37c4428509524ee576920a98381f3e4872493Nick Pelly
148547e37c4428509524ee576920a98381f3e4872493Nick PellyDESCRIPTION
148647e37c4428509524ee576920a98381f3e4872493Nick Pelly  OMX Get Parameter method implementation
148747e37c4428509524ee576920a98381f3e4872493Nick Pelly
148847e37c4428509524ee576920a98381f3e4872493Nick PellyPARAMETERS
148947e37c4428509524ee576920a98381f3e4872493Nick Pelly  <TBD>.
149047e37c4428509524ee576920a98381f3e4872493Nick Pelly
149147e37c4428509524ee576920a98381f3e4872493Nick PellyRETURN VALUE
149247e37c4428509524ee576920a98381f3e4872493Nick Pelly  Error None if successful.
149347e37c4428509524ee576920a98381f3e4872493Nick Pelly
149447e37c4428509524ee576920a98381f3e4872493Nick Pelly========================================================================== */
149547e37c4428509524ee576920a98381f3e4872493Nick PellyOMX_ERRORTYPE  omx_video::get_parameter(OMX_IN OMX_HANDLETYPE     hComp,
149647e37c4428509524ee576920a98381f3e4872493Nick Pelly                                        OMX_IN OMX_INDEXTYPE paramIndex,
149747e37c4428509524ee576920a98381f3e4872493Nick Pelly                                        OMX_INOUT OMX_PTR     paramData)
149847e37c4428509524ee576920a98381f3e4872493Nick Pelly{
149947e37c4428509524ee576920a98381f3e4872493Nick Pelly  OMX_ERRORTYPE eRet = OMX_ErrorNone;
150047e37c4428509524ee576920a98381f3e4872493Nick Pelly  unsigned int height=0,width = 0;
150147e37c4428509524ee576920a98381f3e4872493Nick Pelly
150247e37c4428509524ee576920a98381f3e4872493Nick Pelly  DEBUG_PRINT_LOW("get_parameter: \n");
150347e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(m_state == OMX_StateInvalid)
150447e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
150547e37c4428509524ee576920a98381f3e4872493Nick Pelly    DEBUG_PRINT_ERROR("ERROR: Get Param in Invalid State\n");
150647e37c4428509524ee576920a98381f3e4872493Nick Pelly    return OMX_ErrorInvalidState;
150747e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
150847e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(paramData == NULL)
150947e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
151047e37c4428509524ee576920a98381f3e4872493Nick Pelly    DEBUG_PRINT_ERROR("ERROR: Get Param in Invalid paramData \n");
151147e37c4428509524ee576920a98381f3e4872493Nick Pelly    return OMX_ErrorBadParameter;
151247e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
151347e37c4428509524ee576920a98381f3e4872493Nick Pelly  switch(paramIndex)
151447e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
151547e37c4428509524ee576920a98381f3e4872493Nick Pelly  case OMX_IndexParamPortDefinition:
151647e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
151747e37c4428509524ee576920a98381f3e4872493Nick Pelly      OMX_PARAM_PORTDEFINITIONTYPE *portDefn;
151847e37c4428509524ee576920a98381f3e4872493Nick Pelly      portDefn = (OMX_PARAM_PORTDEFINITIONTYPE *) paramData;
151947e37c4428509524ee576920a98381f3e4872493Nick Pelly
152047e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamPortDefinition\n");
152147e37c4428509524ee576920a98381f3e4872493Nick Pelly      if(portDefn->nPortIndex == (OMX_U32) PORT_INDEX_IN)
152247e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
1523826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        DEBUG_PRINT_LOW("m_sInPortDef: size = %d, min cnt = %d, actual cnt = %d",
1524826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev            m_sInPortDef.nBufferSize, m_sInPortDef.nBufferCountMin,
1525826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev            m_sInPortDef.nBufferCountActual);
152647e37c4428509524ee576920a98381f3e4872493Nick Pelly        memcpy(portDefn, &m_sInPortDef, sizeof(m_sInPortDef));
1527826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#ifdef _ANDROID_ICS_
1528826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        if(meta_mode_enable)
1529826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        {
1530826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev          portDefn->nBufferSize = sizeof(encoder_media_buffer_type);
1531826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        }
15327783f07680c4e868295efbd0cf55a1622a106522Deva Ramasubramanian        if(secure_session) {
15337783f07680c4e868295efbd0cf55a1622a106522Deva Ramasubramanian          portDefn->format.video.eColorFormat =
15347783f07680c4e868295efbd0cf55a1622a106522Deva Ramasubramanian            (OMX_COLOR_FORMATTYPE)secure_color_format;
15357783f07680c4e868295efbd0cf55a1622a106522Deva Ramasubramanian        }
15367783f07680c4e868295efbd0cf55a1622a106522Deva Ramasubramanian        else if (mUseProxyColorFormat) {
15377eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George            portDefn->format.video.eColorFormat =
15387eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George              (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FormatAndroidOpaque;
1539826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        }
1540826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#endif
154147e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
154247e37c4428509524ee576920a98381f3e4872493Nick Pelly      else if(portDefn->nPortIndex == (OMX_U32) PORT_INDEX_OUT)
154347e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
1544826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        dev_get_buf_req (&m_sOutPortDef.nBufferCountMin,
1545826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev                         &m_sOutPortDef.nBufferCountActual,
1546826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev                         &m_sOutPortDef.nBufferSize,
1547826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev                         m_sOutPortDef.nPortIndex);
1548826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        DEBUG_PRINT_LOW("m_sOutPortDef: size = %d, min cnt = %d, actual cnt = %d",
1549826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev            m_sOutPortDef.nBufferSize, m_sOutPortDef.nBufferCountMin,
1550826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev            m_sOutPortDef.nBufferCountActual);
155147e37c4428509524ee576920a98381f3e4872493Nick Pelly        memcpy(portDefn, &m_sOutPortDef, sizeof(m_sOutPortDef));
155247e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
155347e37c4428509524ee576920a98381f3e4872493Nick Pelly      else
155447e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
155547e37c4428509524ee576920a98381f3e4872493Nick Pelly        DEBUG_PRINT_ERROR("ERROR: GetParameter called on Bad Port Index");
155647e37c4428509524ee576920a98381f3e4872493Nick Pelly        eRet = OMX_ErrorBadPortIndex;
155747e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
155847e37c4428509524ee576920a98381f3e4872493Nick Pelly      break;
155947e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
156047e37c4428509524ee576920a98381f3e4872493Nick Pelly  case OMX_IndexParamVideoInit:
156147e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
156247e37c4428509524ee576920a98381f3e4872493Nick Pelly      OMX_PORT_PARAM_TYPE *portParamType =
156347e37c4428509524ee576920a98381f3e4872493Nick Pelly      (OMX_PORT_PARAM_TYPE *) paramData;
156447e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoInit\n");
156547e37c4428509524ee576920a98381f3e4872493Nick Pelly
156647e37c4428509524ee576920a98381f3e4872493Nick Pelly      memcpy(portParamType, &m_sPortParam, sizeof(m_sPortParam));
156747e37c4428509524ee576920a98381f3e4872493Nick Pelly      break;
156847e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
156947e37c4428509524ee576920a98381f3e4872493Nick Pelly  case OMX_IndexParamVideoPortFormat:
157047e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
157147e37c4428509524ee576920a98381f3e4872493Nick Pelly      OMX_VIDEO_PARAM_PORTFORMATTYPE *portFmt =
157247e37c4428509524ee576920a98381f3e4872493Nick Pelly      (OMX_VIDEO_PARAM_PORTFORMATTYPE *)paramData;
157347e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoPortFormat\n");
157447e37c4428509524ee576920a98381f3e4872493Nick Pelly
157547e37c4428509524ee576920a98381f3e4872493Nick Pelly      if(portFmt->nPortIndex == (OMX_U32) PORT_INDEX_IN)
157647e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
1577826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev          int index = portFmt->nIndex;
1578826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev
1579edbb785486ef8a0bbff7c0ea60c374149df9ab7cHaynes Mathew George          if (index > 1) {
1580edbb785486ef8a0bbff7c0ea60c374149df9ab7cHaynes Mathew George              eRet = OMX_ErrorNoMore;
1581edbb785486ef8a0bbff7c0ea60c374149df9ab7cHaynes Mathew George          } else {
1582edbb785486ef8a0bbff7c0ea60c374149df9ab7cHaynes Mathew George              memcpy(portFmt, &m_sInPortFormat, sizeof(m_sInPortFormat));
1583826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#ifdef _ANDROID_ICS_
1584edbb785486ef8a0bbff7c0ea60c374149df9ab7cHaynes Mathew George              if (index == 1) {
1585edbb785486ef8a0bbff7c0ea60c374149df9ab7cHaynes Mathew George                  //we support two formats
1586edbb785486ef8a0bbff7c0ea60c374149df9ab7cHaynes Mathew George                  //index 0 - YUV420SP
1587edbb785486ef8a0bbff7c0ea60c374149df9ab7cHaynes Mathew George                  //index 1 - opaque which internally maps to YUV420SP.
1588edbb785486ef8a0bbff7c0ea60c374149df9ab7cHaynes Mathew George                  //this can be extended in the future
1589edbb785486ef8a0bbff7c0ea60c374149df9ab7cHaynes Mathew George                  portFmt->nIndex = index; //restore index set from client
1590edbb785486ef8a0bbff7c0ea60c374149df9ab7cHaynes Mathew George                  portFmt->eColorFormat =
1591edbb785486ef8a0bbff7c0ea60c374149df9ab7cHaynes Mathew George                    (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FormatAndroidOpaque;
1592edbb785486ef8a0bbff7c0ea60c374149df9ab7cHaynes Mathew George              }
1593826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev          }
1594826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#endif
159547e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
159647e37c4428509524ee576920a98381f3e4872493Nick Pelly      else if(portFmt->nPortIndex == (OMX_U32) PORT_INDEX_OUT)
159747e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
159847e37c4428509524ee576920a98381f3e4872493Nick Pelly        memcpy(portFmt, &m_sOutPortFormat, sizeof(m_sOutPortFormat));
159947e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
160047e37c4428509524ee576920a98381f3e4872493Nick Pelly      else
160147e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
160247e37c4428509524ee576920a98381f3e4872493Nick Pelly        DEBUG_PRINT_ERROR("ERROR: GetParameter called on Bad Port Index");
160347e37c4428509524ee576920a98381f3e4872493Nick Pelly        eRet = OMX_ErrorBadPortIndex;
160447e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
160547e37c4428509524ee576920a98381f3e4872493Nick Pelly      break;
160647e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
160747e37c4428509524ee576920a98381f3e4872493Nick Pelly  case OMX_IndexParamVideoBitrate:
160847e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
160947e37c4428509524ee576920a98381f3e4872493Nick Pelly      OMX_VIDEO_PARAM_BITRATETYPE* pParam = (OMX_VIDEO_PARAM_BITRATETYPE*)paramData;
161047e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoBitrate\n");
161147e37c4428509524ee576920a98381f3e4872493Nick Pelly
161247e37c4428509524ee576920a98381f3e4872493Nick Pelly      if(pParam->nPortIndex == (OMX_U32) PORT_INDEX_OUT)
161347e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
161447e37c4428509524ee576920a98381f3e4872493Nick Pelly        memcpy(pParam, &m_sParamBitrate, sizeof(m_sParamBitrate));
161547e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
161647e37c4428509524ee576920a98381f3e4872493Nick Pelly      else
161747e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
161847e37c4428509524ee576920a98381f3e4872493Nick Pelly        DEBUG_PRINT_ERROR("ERROR: GetParameter called on Bad Port Index");
161947e37c4428509524ee576920a98381f3e4872493Nick Pelly        eRet = OMX_ErrorBadPortIndex;
162047e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
162147e37c4428509524ee576920a98381f3e4872493Nick Pelly
162247e37c4428509524ee576920a98381f3e4872493Nick Pelly      break;
162347e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
162447e37c4428509524ee576920a98381f3e4872493Nick Pelly  case OMX_IndexParamVideoMpeg4:
162547e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
162647e37c4428509524ee576920a98381f3e4872493Nick Pelly      OMX_VIDEO_PARAM_MPEG4TYPE* pParam = (OMX_VIDEO_PARAM_MPEG4TYPE*)paramData;
162747e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoMpeg4\n");
162847e37c4428509524ee576920a98381f3e4872493Nick Pelly      memcpy(pParam, &m_sParamMPEG4, sizeof(m_sParamMPEG4));
162947e37c4428509524ee576920a98381f3e4872493Nick Pelly      break;
163047e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
163147e37c4428509524ee576920a98381f3e4872493Nick Pelly  case OMX_IndexParamVideoH263:
163247e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
163347e37c4428509524ee576920a98381f3e4872493Nick Pelly      OMX_VIDEO_PARAM_H263TYPE* pParam = (OMX_VIDEO_PARAM_H263TYPE*)paramData;
163447e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoH263\n");
163547e37c4428509524ee576920a98381f3e4872493Nick Pelly      memcpy(pParam, &m_sParamH263, sizeof(m_sParamH263));
163647e37c4428509524ee576920a98381f3e4872493Nick Pelly      break;
163747e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
163847e37c4428509524ee576920a98381f3e4872493Nick Pelly  case OMX_IndexParamVideoAvc:
163947e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
164047e37c4428509524ee576920a98381f3e4872493Nick Pelly      OMX_VIDEO_PARAM_AVCTYPE* pParam = (OMX_VIDEO_PARAM_AVCTYPE*)paramData;
164147e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoAvc\n");
164247e37c4428509524ee576920a98381f3e4872493Nick Pelly      memcpy(pParam, &m_sParamAVC, sizeof(m_sParamAVC));
164347e37c4428509524ee576920a98381f3e4872493Nick Pelly      break;
164447e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
164547e37c4428509524ee576920a98381f3e4872493Nick Pelly  case OMX_IndexParamVideoProfileLevelQuerySupported:
164647e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
164747e37c4428509524ee576920a98381f3e4872493Nick Pelly      OMX_VIDEO_PARAM_PROFILELEVELTYPE* pParam = (OMX_VIDEO_PARAM_PROFILELEVELTYPE*)paramData;
164847e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported\n");
1649826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      eRet = get_supported_profile_level(pParam);
1650826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      if(eRet)
1651826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        DEBUG_PRINT_ERROR("Invalid entry returned from get_supported_profile_level %d, %d",
1652826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev                          pParam->eProfile, pParam->eLevel);
165347e37c4428509524ee576920a98381f3e4872493Nick Pelly      break;
1654826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev     }
165547e37c4428509524ee576920a98381f3e4872493Nick Pelly  case OMX_IndexParamVideoProfileLevelCurrent:
165647e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
165747e37c4428509524ee576920a98381f3e4872493Nick Pelly      OMX_VIDEO_PARAM_PROFILELEVELTYPE* pParam = (OMX_VIDEO_PARAM_PROFILELEVELTYPE*)paramData;
165847e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoProfileLevelCurrent\n");
165947e37c4428509524ee576920a98381f3e4872493Nick Pelly      memcpy(pParam, &m_sParamProfileLevel, sizeof(m_sParamProfileLevel));
166047e37c4428509524ee576920a98381f3e4872493Nick Pelly      break;
166147e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
166247e37c4428509524ee576920a98381f3e4872493Nick Pelly    /*Component should support this port definition*/
166347e37c4428509524ee576920a98381f3e4872493Nick Pelly  case OMX_IndexParamAudioInit:
166447e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
166547e37c4428509524ee576920a98381f3e4872493Nick Pelly      OMX_PORT_PARAM_TYPE *audioPortParamType = (OMX_PORT_PARAM_TYPE *) paramData;
166647e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamAudioInit\n");
166747e37c4428509524ee576920a98381f3e4872493Nick Pelly      memcpy(audioPortParamType, &m_sPortParam_audio, sizeof(m_sPortParam_audio));
166847e37c4428509524ee576920a98381f3e4872493Nick Pelly      break;
166947e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
167047e37c4428509524ee576920a98381f3e4872493Nick Pelly    /*Component should support this port definition*/
167147e37c4428509524ee576920a98381f3e4872493Nick Pelly  case OMX_IndexParamImageInit:
167247e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
167347e37c4428509524ee576920a98381f3e4872493Nick Pelly      OMX_PORT_PARAM_TYPE *imagePortParamType = (OMX_PORT_PARAM_TYPE *) paramData;
167447e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamImageInit\n");
167547e37c4428509524ee576920a98381f3e4872493Nick Pelly      memcpy(imagePortParamType, &m_sPortParam_img, sizeof(m_sPortParam_img));
167647e37c4428509524ee576920a98381f3e4872493Nick Pelly      break;
167747e37c4428509524ee576920a98381f3e4872493Nick Pelly
167847e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
167947e37c4428509524ee576920a98381f3e4872493Nick Pelly    /*Component should support this port definition*/
168047e37c4428509524ee576920a98381f3e4872493Nick Pelly  case OMX_IndexParamOtherInit:
168147e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
168247e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_ERROR("ERROR: get_parameter: OMX_IndexParamOtherInit %08x\n", paramIndex);
168347e37c4428509524ee576920a98381f3e4872493Nick Pelly      eRet =OMX_ErrorUnsupportedIndex;
168447e37c4428509524ee576920a98381f3e4872493Nick Pelly      break;
168547e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
168647e37c4428509524ee576920a98381f3e4872493Nick Pelly  case OMX_IndexParamStandardComponentRole:
168747e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
168847e37c4428509524ee576920a98381f3e4872493Nick Pelly      OMX_PARAM_COMPONENTROLETYPE *comp_role;
168947e37c4428509524ee576920a98381f3e4872493Nick Pelly      comp_role = (OMX_PARAM_COMPONENTROLETYPE *) paramData;
169047e37c4428509524ee576920a98381f3e4872493Nick Pelly      comp_role->nVersion.nVersion = OMX_SPEC_VERSION;
169147e37c4428509524ee576920a98381f3e4872493Nick Pelly      comp_role->nSize = sizeof(*comp_role);
169247e37c4428509524ee576920a98381f3e4872493Nick Pelly
169347e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_LOW("Getparameter: OMX_IndexParamStandardComponentRole %d\n",paramIndex);
169447e37c4428509524ee576920a98381f3e4872493Nick Pelly      if(NULL != comp_role->cRole)
169547e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
1696826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        strlcpy((char*)comp_role->cRole,(const char*)m_cRole,OMX_MAX_STRINGNAME_SIZE);
169747e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
169847e37c4428509524ee576920a98381f3e4872493Nick Pelly      else
169947e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
170047e37c4428509524ee576920a98381f3e4872493Nick Pelly        DEBUG_PRINT_ERROR("ERROR: Getparameter: OMX_IndexParamStandardComponentRole %d is passed with NULL parameter for role\n",paramIndex);
170147e37c4428509524ee576920a98381f3e4872493Nick Pelly        eRet =OMX_ErrorBadParameter;
170247e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
170347e37c4428509524ee576920a98381f3e4872493Nick Pelly      break;
170447e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
170547e37c4428509524ee576920a98381f3e4872493Nick Pelly    /* Added for parameter test */
170647e37c4428509524ee576920a98381f3e4872493Nick Pelly  case OMX_IndexParamPriorityMgmt:
170747e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
170847e37c4428509524ee576920a98381f3e4872493Nick Pelly
170947e37c4428509524ee576920a98381f3e4872493Nick Pelly      OMX_PRIORITYMGMTTYPE *priorityMgmType = (OMX_PRIORITYMGMTTYPE *) paramData;
171047e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamPriorityMgmt\n");
171147e37c4428509524ee576920a98381f3e4872493Nick Pelly      memcpy(priorityMgmType, &m_sPriorityMgmt, sizeof(m_sPriorityMgmt));
171247e37c4428509524ee576920a98381f3e4872493Nick Pelly      break;
171347e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
171447e37c4428509524ee576920a98381f3e4872493Nick Pelly    /* Added for parameter test */
171547e37c4428509524ee576920a98381f3e4872493Nick Pelly  case OMX_IndexParamCompBufferSupplier:
171647e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
171747e37c4428509524ee576920a98381f3e4872493Nick Pelly      OMX_PARAM_BUFFERSUPPLIERTYPE *bufferSupplierType = (OMX_PARAM_BUFFERSUPPLIERTYPE*) paramData;
171847e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamCompBufferSupplier\n");
171947e37c4428509524ee576920a98381f3e4872493Nick Pelly      if(bufferSupplierType->nPortIndex ==(OMX_U32) PORT_INDEX_IN)
172047e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
172147e37c4428509524ee576920a98381f3e4872493Nick Pelly        memcpy(bufferSupplierType, &m_sInBufSupplier, sizeof(m_sInBufSupplier));
172247e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
172347e37c4428509524ee576920a98381f3e4872493Nick Pelly      else if(bufferSupplierType->nPortIndex ==(OMX_U32) PORT_INDEX_OUT)
172447e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
172547e37c4428509524ee576920a98381f3e4872493Nick Pelly        memcpy(bufferSupplierType, &m_sOutBufSupplier, sizeof(m_sOutBufSupplier));
172647e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
172747e37c4428509524ee576920a98381f3e4872493Nick Pelly      else
172847e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
172947e37c4428509524ee576920a98381f3e4872493Nick Pelly        DEBUG_PRINT_ERROR("ERROR: GetParameter called on Bad Port Index");
173047e37c4428509524ee576920a98381f3e4872493Nick Pelly        eRet = OMX_ErrorBadPortIndex;
173147e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
173247e37c4428509524ee576920a98381f3e4872493Nick Pelly      break;
173347e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
173447e37c4428509524ee576920a98381f3e4872493Nick Pelly
173547e37c4428509524ee576920a98381f3e4872493Nick Pelly  case OMX_IndexParamVideoQuantization:
173647e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
173747e37c4428509524ee576920a98381f3e4872493Nick Pelly      OMX_VIDEO_PARAM_QUANTIZATIONTYPE *session_qp = (OMX_VIDEO_PARAM_QUANTIZATIONTYPE*) paramData;
173847e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoQuantization\n");
173947e37c4428509524ee576920a98381f3e4872493Nick Pelly      memcpy(session_qp, &m_sSessionQuantization, sizeof(m_sSessionQuantization));
174047e37c4428509524ee576920a98381f3e4872493Nick Pelly      break;
174147e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
174247e37c4428509524ee576920a98381f3e4872493Nick Pelly
1743826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    case OMX_IndexParamVideoErrorCorrection:
1744826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    {
1745826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE* errorresilience = (OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE*)paramData;
1746826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      DEBUG_PRINT_LOW("OMX_IndexParamVideoErrorCorrection\n");
1747826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      errorresilience->bEnableHEC = m_sErrorCorrection.bEnableHEC;
1748826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      errorresilience->bEnableResync = m_sErrorCorrection.bEnableResync;
1749826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      errorresilience->nResynchMarkerSpacing = m_sErrorCorrection.nResynchMarkerSpacing;
1750826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      break;
1751826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    }
1752826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  case OMX_IndexParamVideoIntraRefresh:
1753826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    {
1754826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      OMX_VIDEO_PARAM_INTRAREFRESHTYPE* intrarefresh = (OMX_VIDEO_PARAM_INTRAREFRESHTYPE*)paramData;
1755826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      DEBUG_PRINT_LOW("OMX_IndexParamVideoIntraRefresh\n");
1756826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      DEBUG_PRINT_ERROR("OMX_IndexParamVideoIntraRefresh GET\n");
1757826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      intrarefresh->eRefreshMode = m_sIntraRefresh.eRefreshMode;
1758826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      intrarefresh->nCirMBs = m_sIntraRefresh.nCirMBs;
1759826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      break;
1760826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    }
176147e37c4428509524ee576920a98381f3e4872493Nick Pelly  case OMX_QcomIndexPortDefn:
176247e37c4428509524ee576920a98381f3e4872493Nick Pelly    //TODO
176347e37c4428509524ee576920a98381f3e4872493Nick Pelly    break;
176447e37c4428509524ee576920a98381f3e4872493Nick Pelly  case OMX_COMPONENT_CAPABILITY_TYPE_INDEX:
176547e37c4428509524ee576920a98381f3e4872493Nick Pelly   {
176647e37c4428509524ee576920a98381f3e4872493Nick Pelly        OMXComponentCapabilityFlagsType *pParam = reinterpret_cast<OMXComponentCapabilityFlagsType*>(paramData);
176747e37c4428509524ee576920a98381f3e4872493Nick Pelly        DEBUG_PRINT_LOW("get_parameter: OMX_COMPONENT_CAPABILITY_TYPE_INDEX\n");
176847e37c4428509524ee576920a98381f3e4872493Nick Pelly        pParam->iIsOMXComponentMultiThreaded = OMX_TRUE;
176947e37c4428509524ee576920a98381f3e4872493Nick Pelly        pParam->iOMXComponentSupportsExternalOutputBufferAlloc = OMX_FALSE;
177047e37c4428509524ee576920a98381f3e4872493Nick Pelly        pParam->iOMXComponentSupportsExternalInputBufferAlloc = OMX_TRUE;
177147e37c4428509524ee576920a98381f3e4872493Nick Pelly        pParam->iOMXComponentSupportsMovableInputBuffers = OMX_TRUE;
177247e37c4428509524ee576920a98381f3e4872493Nick Pelly        pParam->iOMXComponentUsesNALStartCodes = OMX_TRUE;
177347e37c4428509524ee576920a98381f3e4872493Nick Pelly        pParam->iOMXComponentSupportsPartialFrames = OMX_FALSE;
177447e37c4428509524ee576920a98381f3e4872493Nick Pelly        pParam->iOMXComponentCanHandleIncompleteFrames = OMX_FALSE;
177547e37c4428509524ee576920a98381f3e4872493Nick Pelly        pParam->iOMXComponentUsesFullAVCFrames = OMX_FALSE;
177647e37c4428509524ee576920a98381f3e4872493Nick Pelly        m_use_input_pmem = OMX_TRUE;
177747e37c4428509524ee576920a98381f3e4872493Nick Pelly        DEBUG_PRINT_LOW("Supporting capability index in encoder node");
177847e37c4428509524ee576920a98381f3e4872493Nick Pelly        break;
177947e37c4428509524ee576920a98381f3e4872493Nick Pelly   }
1780826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#ifndef MAX_RES_720P
1781826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  case OMX_QcomIndexParamIndexExtraDataType:
178247e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
1783826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      DEBUG_PRINT_LOW("get_parameter: OMX_QcomIndexParamIndexExtraDataType");
1784826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      QOMX_INDEXEXTRADATATYPE *pParam = (QOMX_INDEXEXTRADATATYPE *)paramData;
1785826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      if (pParam->nIndex == (OMX_INDEXTYPE)OMX_ExtraDataVideoEncoderSliceInfo)
1786826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      {
1787826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        if (pParam->nPortIndex == PORT_INDEX_OUT)
178847e37c4428509524ee576920a98381f3e4872493Nick Pelly        {
1789826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev          pParam->bEnabled =
1790826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev             (OMX_BOOL)((m_sExtraData & VEN_EXTRADATA_SLICEINFO) ? 1 : 0);
1791826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev          DEBUG_PRINT_HIGH("Slice Info extradata %d", pParam->bEnabled);
179247e37c4428509524ee576920a98381f3e4872493Nick Pelly        }
179347e37c4428509524ee576920a98381f3e4872493Nick Pelly        else
179447e37c4428509524ee576920a98381f3e4872493Nick Pelly        {
1795826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev          DEBUG_PRINT_ERROR("get_parameter: slice information is "
1796826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev              "valid for output port only");
1797826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev          eRet =OMX_ErrorUnsupportedIndex;
179847e37c4428509524ee576920a98381f3e4872493Nick Pelly        }
1799826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      }
1800826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      else
1801826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      {
1802826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        DEBUG_PRINT_ERROR("get_parameter: unsupported index (%x), "
1803826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev            "only slice information extradata is supported", pParam->nIndex);
1804826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        eRet =OMX_ErrorUnsupportedIndex;
1805826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      }
1806826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      break;
1807826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    }
1808826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#endif
1809826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  case QOMX_IndexParamVideoSyntaxHdr:
1810826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    {
1811826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev       DEBUG_PRINT_HIGH("QOMX_IndexParamVideoSyntaxHdr");
1812826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev       QOMX_EXTNINDEX_PARAMTYPE* pParam =
1813826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev          reinterpret_cast<QOMX_EXTNINDEX_PARAMTYPE*>(paramData);
1814826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev       BITMASK_SET(&m_flags, OMX_COMPONENT_LOADED_START_PENDING);
1815826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev       if(dev_loaded_start())
1816826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev       {
1817826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev         DEBUG_PRINT_LOW("device start successful");
1818826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev       }
1819826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev       else
1820826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev       {
1821826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev         DEBUG_PRINT_ERROR("device start failed");
1822826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev         BITMASK_CLEAR(&m_flags, OMX_COMPONENT_LOADED_START_PENDING);
1823826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev         return OMX_ErrorHardware;
1824826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev       }
1825826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev       if(dev_get_seq_hdr(pParam->pData,
1826826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev            (unsigned)(pParam->nSize - sizeof(QOMX_EXTNINDEX_PARAMTYPE)),
1827826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev            (unsigned *)&pParam->nDataSize))
1828826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev       {
1829826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev         DEBUG_PRINT_HIGH("get syntax header successful (hdrlen = %d)",
1830826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev            pParam->nDataSize);
1831826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev         for (unsigned i = 0; i < pParam->nDataSize; i++) {
1832826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev           DEBUG_PRINT_LOW("Header[%d] = %x", i, *((char *)pParam->pData + i));
1833826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev         }
1834826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev       }
1835826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev       else
1836826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev       {
1837826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev         DEBUG_PRINT_ERROR("Error returned from GetSyntaxHeader()");
1838826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev         eRet = OMX_ErrorHardware;
1839826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev       }
1840826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev       BITMASK_SET(&m_flags, OMX_COMPONENT_LOADED_STOP_PENDING);
1841826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev       if(dev_loaded_stop())
1842826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev       {
1843826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev         DEBUG_PRINT_LOW("device stop successful");
1844826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev       }
1845826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev       else
1846826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev       {
1847826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev         DEBUG_PRINT_ERROR("device stop failed");
1848826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev         BITMASK_CLEAR(&m_flags, OMX_COMPONENT_LOADED_STOP_PENDING);
1849826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev         eRet = OMX_ErrorHardware;
1850826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev       }
1851826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev       break;
185247e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
1853826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  case OMX_IndexParamVideoSliceFMO:
185447e37c4428509524ee576920a98381f3e4872493Nick Pelly  default:
185547e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
185647e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_ERROR("ERROR: get_parameter: unknown param %08x\n", paramIndex);
185747e37c4428509524ee576920a98381f3e4872493Nick Pelly      eRet =OMX_ErrorUnsupportedIndex;
185847e37c4428509524ee576920a98381f3e4872493Nick Pelly      break;
185947e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
186047e37c4428509524ee576920a98381f3e4872493Nick Pelly
186147e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
186247e37c4428509524ee576920a98381f3e4872493Nick Pelly
186347e37c4428509524ee576920a98381f3e4872493Nick Pelly  return eRet;
186447e37c4428509524ee576920a98381f3e4872493Nick Pelly
186547e37c4428509524ee576920a98381f3e4872493Nick Pelly}
186647e37c4428509524ee576920a98381f3e4872493Nick Pelly/* ======================================================================
186747e37c4428509524ee576920a98381f3e4872493Nick PellyFUNCTION
186847e37c4428509524ee576920a98381f3e4872493Nick Pelly  omx_video::GetConfig
186947e37c4428509524ee576920a98381f3e4872493Nick Pelly
187047e37c4428509524ee576920a98381f3e4872493Nick PellyDESCRIPTION
187147e37c4428509524ee576920a98381f3e4872493Nick Pelly  OMX Get Config Method implementation.
187247e37c4428509524ee576920a98381f3e4872493Nick Pelly
187347e37c4428509524ee576920a98381f3e4872493Nick PellyPARAMETERS
187447e37c4428509524ee576920a98381f3e4872493Nick Pelly  <TBD>.
187547e37c4428509524ee576920a98381f3e4872493Nick Pelly
187647e37c4428509524ee576920a98381f3e4872493Nick PellyRETURN VALUE
187747e37c4428509524ee576920a98381f3e4872493Nick Pelly  OMX Error None if successful.
187847e37c4428509524ee576920a98381f3e4872493Nick Pelly
187947e37c4428509524ee576920a98381f3e4872493Nick Pelly========================================================================== */
188047e37c4428509524ee576920a98381f3e4872493Nick PellyOMX_ERRORTYPE  omx_video::get_config(OMX_IN OMX_HANDLETYPE      hComp,
188147e37c4428509524ee576920a98381f3e4872493Nick Pelly                                     OMX_IN OMX_INDEXTYPE configIndex,
188247e37c4428509524ee576920a98381f3e4872493Nick Pelly                                     OMX_INOUT OMX_PTR     configData)
188347e37c4428509524ee576920a98381f3e4872493Nick Pelly{
188447e37c4428509524ee576920a98381f3e4872493Nick Pelly  ////////////////////////////////////////////////////////////////
188547e37c4428509524ee576920a98381f3e4872493Nick Pelly  // Supported Config Index           Type
188647e37c4428509524ee576920a98381f3e4872493Nick Pelly  // =============================================================
188747e37c4428509524ee576920a98381f3e4872493Nick Pelly  // OMX_IndexConfigVideoBitrate      OMX_VIDEO_CONFIG_BITRATETYPE
188847e37c4428509524ee576920a98381f3e4872493Nick Pelly  // OMX_IndexConfigVideoFramerate    OMX_CONFIG_FRAMERATETYPE
188947e37c4428509524ee576920a98381f3e4872493Nick Pelly  // OMX_IndexConfigCommonRotate      OMX_CONFIG_ROTATIONTYPE
189047e37c4428509524ee576920a98381f3e4872493Nick Pelly  ////////////////////////////////////////////////////////////////
189147e37c4428509524ee576920a98381f3e4872493Nick Pelly
189247e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(configData == NULL)
189347e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
189447e37c4428509524ee576920a98381f3e4872493Nick Pelly    DEBUG_PRINT_ERROR("ERROR: param is null");
189547e37c4428509524ee576920a98381f3e4872493Nick Pelly    return OMX_ErrorBadParameter;
189647e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
189747e37c4428509524ee576920a98381f3e4872493Nick Pelly
189847e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(m_state == OMX_StateInvalid)
189947e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
190047e37c4428509524ee576920a98381f3e4872493Nick Pelly    DEBUG_PRINT_ERROR("ERROR: can't be in invalid state");
190147e37c4428509524ee576920a98381f3e4872493Nick Pelly    return OMX_ErrorIncorrectStateOperation;
190247e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
190347e37c4428509524ee576920a98381f3e4872493Nick Pelly
190447e37c4428509524ee576920a98381f3e4872493Nick Pelly  //@todo need to validate params
190547e37c4428509524ee576920a98381f3e4872493Nick Pelly  switch(configIndex)
190647e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
190747e37c4428509524ee576920a98381f3e4872493Nick Pelly  case OMX_IndexConfigVideoBitrate:
190847e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
190947e37c4428509524ee576920a98381f3e4872493Nick Pelly      OMX_VIDEO_CONFIG_BITRATETYPE* pParam = reinterpret_cast<OMX_VIDEO_CONFIG_BITRATETYPE*>(configData);
191047e37c4428509524ee576920a98381f3e4872493Nick Pelly      memcpy(pParam, &m_sConfigBitrate, sizeof(m_sConfigBitrate));
191147e37c4428509524ee576920a98381f3e4872493Nick Pelly      break;
191247e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
191347e37c4428509524ee576920a98381f3e4872493Nick Pelly  case OMX_IndexConfigVideoFramerate:
191447e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
191547e37c4428509524ee576920a98381f3e4872493Nick Pelly      OMX_CONFIG_FRAMERATETYPE* pParam = reinterpret_cast<OMX_CONFIG_FRAMERATETYPE*>(configData);
191647e37c4428509524ee576920a98381f3e4872493Nick Pelly      memcpy(pParam, &m_sConfigFramerate, sizeof(m_sConfigFramerate));
191747e37c4428509524ee576920a98381f3e4872493Nick Pelly      break;
191847e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
191947e37c4428509524ee576920a98381f3e4872493Nick Pelly  case OMX_IndexConfigCommonRotate:
192047e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
192147e37c4428509524ee576920a98381f3e4872493Nick Pelly      OMX_CONFIG_ROTATIONTYPE* pParam = reinterpret_cast<OMX_CONFIG_ROTATIONTYPE*>(configData);
192247e37c4428509524ee576920a98381f3e4872493Nick Pelly      memcpy(pParam, &m_sConfigFrameRotation, sizeof(m_sConfigFrameRotation));
192347e37c4428509524ee576920a98381f3e4872493Nick Pelly      break;
192447e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
1925826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  case QOMX_IndexConfigVideoIntraperiod:
1926826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    {
1927826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      DEBUG_PRINT_LOW("get_config:QOMX_IndexConfigVideoIntraperiod\n");
1928826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      QOMX_VIDEO_INTRAPERIODTYPE* pParam = reinterpret_cast<QOMX_VIDEO_INTRAPERIODTYPE*>(configData);
1929826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      memcpy(pParam, &m_sIntraperiod, sizeof(m_sIntraperiod));
1930826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      break;
1931826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    }
193247e37c4428509524ee576920a98381f3e4872493Nick Pelly  default:
193347e37c4428509524ee576920a98381f3e4872493Nick Pelly    DEBUG_PRINT_ERROR("ERROR: unsupported index %d", (int) configIndex);
193447e37c4428509524ee576920a98381f3e4872493Nick Pelly    return OMX_ErrorUnsupportedIndex;
193547e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
193647e37c4428509524ee576920a98381f3e4872493Nick Pelly  return OMX_ErrorNone;
193747e37c4428509524ee576920a98381f3e4872493Nick Pelly
193847e37c4428509524ee576920a98381f3e4872493Nick Pelly}
193947e37c4428509524ee576920a98381f3e4872493Nick Pelly
194047e37c4428509524ee576920a98381f3e4872493Nick Pelly/* ======================================================================
194147e37c4428509524ee576920a98381f3e4872493Nick PellyFUNCTION
194247e37c4428509524ee576920a98381f3e4872493Nick Pelly  omx_video::GetExtensionIndex
194347e37c4428509524ee576920a98381f3e4872493Nick Pelly
194447e37c4428509524ee576920a98381f3e4872493Nick PellyDESCRIPTION
194547e37c4428509524ee576920a98381f3e4872493Nick Pelly  OMX GetExtensionIndex method implementaion.  <TBD>
194647e37c4428509524ee576920a98381f3e4872493Nick Pelly
194747e37c4428509524ee576920a98381f3e4872493Nick PellyPARAMETERS
194847e37c4428509524ee576920a98381f3e4872493Nick Pelly  <TBD>.
194947e37c4428509524ee576920a98381f3e4872493Nick Pelly
195047e37c4428509524ee576920a98381f3e4872493Nick PellyRETURN VALUE
195147e37c4428509524ee576920a98381f3e4872493Nick Pelly  OMX Error None if everything successful.
195247e37c4428509524ee576920a98381f3e4872493Nick Pelly
195347e37c4428509524ee576920a98381f3e4872493Nick Pelly========================================================================== */
195447e37c4428509524ee576920a98381f3e4872493Nick PellyOMX_ERRORTYPE  omx_video::get_extension_index(OMX_IN OMX_HANDLETYPE      hComp,
195547e37c4428509524ee576920a98381f3e4872493Nick Pelly                                              OMX_IN OMX_STRING      paramName,
195647e37c4428509524ee576920a98381f3e4872493Nick Pelly                                              OMX_OUT OMX_INDEXTYPE* indexType)
195747e37c4428509524ee576920a98381f3e4872493Nick Pelly{
19583145f89c1398e32bb7fc6cc03866388f42d2bad3Deva Ramasubramanian  char *extns[] = {
19593145f89c1398e32bb7fc6cc03866388f42d2bad3Deva Ramasubramanian    "OMX.QCOM.index.param.SliceDeliveryMode",
19603145f89c1398e32bb7fc6cc03866388f42d2bad3Deva Ramasubramanian    "OMX.google.android.index.storeMetaDataInBuffers",
19612d1c6fa918d6d3afcb93a25c0e6d60cac8365275Deva Ramasubramanian    "OMX.google.android.index.prependSPSPPSToIDRFrames",
19622d1c6fa918d6d3afcb93a25c0e6d60cac8365275Deva Ramasubramanian    "OMX.google.android.index.setVUIStreamRestrictFlag"
19633145f89c1398e32bb7fc6cc03866388f42d2bad3Deva Ramasubramanian  };
19643145f89c1398e32bb7fc6cc03866388f42d2bad3Deva Ramasubramanian
196547e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(m_state == OMX_StateInvalid)
196647e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
196747e37c4428509524ee576920a98381f3e4872493Nick Pelly    DEBUG_PRINT_ERROR("ERROR: Get Extension Index in Invalid State\n");
196847e37c4428509524ee576920a98381f3e4872493Nick Pelly    return OMX_ErrorInvalidState;
196947e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
1970826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#ifdef MAX_RES_1080P
19713145f89c1398e32bb7fc6cc03866388f42d2bad3Deva Ramasubramanian  if (!strncmp(paramName, extns[0], strlen(extns[0]))) {
1972826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    *indexType = (OMX_INDEXTYPE)OMX_QcomIndexEnableSliceDeliveryMode;
1973826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    return OMX_ErrorNone;
1974826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  }
1975826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#endif
1976826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#ifdef _ANDROID_ICS_
19773145f89c1398e32bb7fc6cc03866388f42d2bad3Deva Ramasubramanian  if (!strncmp(paramName, extns[1], strlen(extns[1]))) {
1978eb8af24ae2de5fb529f36e7eb1a88648a641edefLajos Molnar        *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamVideoMetaBufferMode;
1979826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        return OMX_ErrorNone;
19803145f89c1398e32bb7fc6cc03866388f42d2bad3Deva Ramasubramanian  } else if (!strncmp(paramName, extns[2], strlen(extns[2]))) {
19813145f89c1398e32bb7fc6cc03866388f42d2bad3Deva Ramasubramanian        *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamSequenceHeaderWithIDR;
19823145f89c1398e32bb7fc6cc03866388f42d2bad3Deva Ramasubramanian        return OMX_ErrorNone;
19832d1c6fa918d6d3afcb93a25c0e6d60cac8365275Deva Ramasubramanian  } else if (!strncmp(paramName, extns[3], strlen(extns[3]))) {
19842d1c6fa918d6d3afcb93a25c0e6d60cac8365275Deva Ramasubramanian        *indexType = (OMX_INDEXTYPE)OMX_QcomIndexParamEnableVUIStreamRestrictFlag;
19852d1c6fa918d6d3afcb93a25c0e6d60cac8365275Deva Ramasubramanian        return OMX_ErrorNone;
1986826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  }
1987826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#endif
198847e37c4428509524ee576920a98381f3e4872493Nick Pelly  return OMX_ErrorNotImplemented;
198947e37c4428509524ee576920a98381f3e4872493Nick Pelly}
199047e37c4428509524ee576920a98381f3e4872493Nick Pelly
199147e37c4428509524ee576920a98381f3e4872493Nick Pelly/* ======================================================================
199247e37c4428509524ee576920a98381f3e4872493Nick PellyFUNCTION
199347e37c4428509524ee576920a98381f3e4872493Nick Pelly  omx_video::GetState
199447e37c4428509524ee576920a98381f3e4872493Nick Pelly
199547e37c4428509524ee576920a98381f3e4872493Nick PellyDESCRIPTION
199647e37c4428509524ee576920a98381f3e4872493Nick Pelly  Returns the state information back to the caller.<TBD>
199747e37c4428509524ee576920a98381f3e4872493Nick Pelly
199847e37c4428509524ee576920a98381f3e4872493Nick PellyPARAMETERS
199947e37c4428509524ee576920a98381f3e4872493Nick Pelly  <TBD>.
200047e37c4428509524ee576920a98381f3e4872493Nick Pelly
200147e37c4428509524ee576920a98381f3e4872493Nick PellyRETURN VALUE
200247e37c4428509524ee576920a98381f3e4872493Nick Pelly  Error None if everything is successful.
200347e37c4428509524ee576920a98381f3e4872493Nick Pelly========================================================================== */
200447e37c4428509524ee576920a98381f3e4872493Nick PellyOMX_ERRORTYPE  omx_video::get_state(OMX_IN OMX_HANDLETYPE  hComp,
200547e37c4428509524ee576920a98381f3e4872493Nick Pelly                                    OMX_OUT OMX_STATETYPE* state)
200647e37c4428509524ee576920a98381f3e4872493Nick Pelly{
200747e37c4428509524ee576920a98381f3e4872493Nick Pelly  *state = m_state;
200847e37c4428509524ee576920a98381f3e4872493Nick Pelly  DEBUG_PRINT_LOW("get_state: Returning the state %d\n",*state);
200947e37c4428509524ee576920a98381f3e4872493Nick Pelly  return OMX_ErrorNone;
201047e37c4428509524ee576920a98381f3e4872493Nick Pelly}
201147e37c4428509524ee576920a98381f3e4872493Nick Pelly
201247e37c4428509524ee576920a98381f3e4872493Nick Pelly/* ======================================================================
201347e37c4428509524ee576920a98381f3e4872493Nick PellyFUNCTION
201447e37c4428509524ee576920a98381f3e4872493Nick Pelly  omx_video::ComponentTunnelRequest
201547e37c4428509524ee576920a98381f3e4872493Nick Pelly
201647e37c4428509524ee576920a98381f3e4872493Nick PellyDESCRIPTION
201747e37c4428509524ee576920a98381f3e4872493Nick Pelly  OMX Component Tunnel Request method implementation. <TBD>
201847e37c4428509524ee576920a98381f3e4872493Nick Pelly
201947e37c4428509524ee576920a98381f3e4872493Nick PellyPARAMETERS
202047e37c4428509524ee576920a98381f3e4872493Nick Pelly  None.
202147e37c4428509524ee576920a98381f3e4872493Nick Pelly
202247e37c4428509524ee576920a98381f3e4872493Nick PellyRETURN VALUE
202347e37c4428509524ee576920a98381f3e4872493Nick Pelly  OMX Error None if everything successful.
202447e37c4428509524ee576920a98381f3e4872493Nick Pelly
202547e37c4428509524ee576920a98381f3e4872493Nick Pelly========================================================================== */
202647e37c4428509524ee576920a98381f3e4872493Nick PellyOMX_ERRORTYPE  omx_video::component_tunnel_request(OMX_IN OMX_HANDLETYPE                hComp,
202747e37c4428509524ee576920a98381f3e4872493Nick Pelly                                                   OMX_IN OMX_U32                        port,
202847e37c4428509524ee576920a98381f3e4872493Nick Pelly                                                   OMX_IN OMX_HANDLETYPE        peerComponent,
202947e37c4428509524ee576920a98381f3e4872493Nick Pelly                                                   OMX_IN OMX_U32                    peerPort,
203047e37c4428509524ee576920a98381f3e4872493Nick Pelly                                                   OMX_INOUT OMX_TUNNELSETUPTYPE* tunnelSetup)
203147e37c4428509524ee576920a98381f3e4872493Nick Pelly{
203247e37c4428509524ee576920a98381f3e4872493Nick Pelly  DEBUG_PRINT_ERROR("ERROR: component_tunnel_request Not Implemented\n");
203347e37c4428509524ee576920a98381f3e4872493Nick Pelly  return OMX_ErrorNotImplemented;
203447e37c4428509524ee576920a98381f3e4872493Nick Pelly}
203547e37c4428509524ee576920a98381f3e4872493Nick Pelly
203647e37c4428509524ee576920a98381f3e4872493Nick Pelly/* ======================================================================
203747e37c4428509524ee576920a98381f3e4872493Nick PellyFUNCTION
203847e37c4428509524ee576920a98381f3e4872493Nick Pelly  omx_video::UseInputBuffer
203947e37c4428509524ee576920a98381f3e4872493Nick Pelly
204047e37c4428509524ee576920a98381f3e4872493Nick PellyDESCRIPTION
204147e37c4428509524ee576920a98381f3e4872493Nick Pelly  Helper function for Use buffer in the input pin
204247e37c4428509524ee576920a98381f3e4872493Nick Pelly
204347e37c4428509524ee576920a98381f3e4872493Nick PellyPARAMETERS
204447e37c4428509524ee576920a98381f3e4872493Nick Pelly  None.
204547e37c4428509524ee576920a98381f3e4872493Nick Pelly
204647e37c4428509524ee576920a98381f3e4872493Nick PellyRETURN VALUE
204747e37c4428509524ee576920a98381f3e4872493Nick Pelly  true/false
204847e37c4428509524ee576920a98381f3e4872493Nick Pelly
204947e37c4428509524ee576920a98381f3e4872493Nick Pelly========================================================================== */
205047e37c4428509524ee576920a98381f3e4872493Nick PellyOMX_ERRORTYPE  omx_video::use_input_buffer(
205147e37c4428509524ee576920a98381f3e4872493Nick Pelly                                          OMX_IN OMX_HANDLETYPE            hComp,
205247e37c4428509524ee576920a98381f3e4872493Nick Pelly                                          OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr,
205347e37c4428509524ee576920a98381f3e4872493Nick Pelly                                          OMX_IN OMX_U32                   port,
205447e37c4428509524ee576920a98381f3e4872493Nick Pelly                                          OMX_IN OMX_PTR                   appData,
205547e37c4428509524ee576920a98381f3e4872493Nick Pelly                                          OMX_IN OMX_U32                   bytes,
205647e37c4428509524ee576920a98381f3e4872493Nick Pelly                                          OMX_IN OMX_U8*                   buffer)
205747e37c4428509524ee576920a98381f3e4872493Nick Pelly{
205847e37c4428509524ee576920a98381f3e4872493Nick Pelly  OMX_ERRORTYPE eRet = OMX_ErrorNone;
205947e37c4428509524ee576920a98381f3e4872493Nick Pelly
206047e37c4428509524ee576920a98381f3e4872493Nick Pelly  unsigned   i = 0;
206147e37c4428509524ee576920a98381f3e4872493Nick Pelly  unsigned char *buf_addr = NULL;
206247e37c4428509524ee576920a98381f3e4872493Nick Pelly
206347e37c4428509524ee576920a98381f3e4872493Nick Pelly  DEBUG_PRINT_HIGH("use_input_buffer: port = %d appData = %p bytes = %d buffer = %p",port,appData,bytes,buffer);
20647783f07680c4e868295efbd0cf55a1622a106522Deva Ramasubramanian  if(bytes != m_sInPortDef.nBufferSize || secure_session)
206547e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
206647e37c4428509524ee576920a98381f3e4872493Nick Pelly    DEBUG_PRINT_ERROR("\nERROR: use_input_buffer: Size Mismatch!! "
206747e37c4428509524ee576920a98381f3e4872493Nick Pelly                      "bytes[%d] != Port.nBufferSize[%d]", bytes, m_sInPortDef.nBufferSize);
206847e37c4428509524ee576920a98381f3e4872493Nick Pelly    return OMX_ErrorBadParameter;
206947e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
207047e37c4428509524ee576920a98381f3e4872493Nick Pelly
207147e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(!m_inp_mem_ptr)
207247e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
207347e37c4428509524ee576920a98381f3e4872493Nick Pelly    input_use_buffer = true;
207447e37c4428509524ee576920a98381f3e4872493Nick Pelly    m_inp_mem_ptr = (OMX_BUFFERHEADERTYPE*) \
207547e37c4428509524ee576920a98381f3e4872493Nick Pelly                    calloc( (sizeof(OMX_BUFFERHEADERTYPE)), m_sInPortDef.nBufferCountActual);
207647e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(m_inp_mem_ptr == NULL)
207747e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
207847e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_ERROR("\nERROR: calloc() Failed for m_inp_mem_ptr");
207947e37c4428509524ee576920a98381f3e4872493Nick Pelly      return OMX_ErrorInsufficientResources;
208047e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
208147e37c4428509524ee576920a98381f3e4872493Nick Pelly
2082826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev
208347e37c4428509524ee576920a98381f3e4872493Nick Pelly    m_pInput_pmem = (struct pmem *) calloc(sizeof (struct pmem), m_sInPortDef.nBufferCountActual);
208447e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(m_pInput_pmem == NULL)
208547e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
208647e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_ERROR("\nERROR: calloc() Failed for m_pInput_pmem");
208747e37c4428509524ee576920a98381f3e4872493Nick Pelly      return OMX_ErrorInsufficientResources;
208847e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
2089826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#ifdef USE_ION
2090826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    m_pInput_ion = (struct venc_ion *) calloc(sizeof (struct venc_ion), m_sInPortDef.nBufferCountActual);
2091826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    if(m_pInput_ion == NULL)
2092826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    {
2093826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      DEBUG_PRINT_ERROR("\nERROR: calloc() Failed for m_pInput_ion");
2094826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      return OMX_ErrorInsufficientResources;
2095826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    }
2096826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#endif
2097826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev
209847e37c4428509524ee576920a98381f3e4872493Nick Pelly    for(i=0; i< m_sInPortDef.nBufferCountActual; i++)
209947e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
210047e37c4428509524ee576920a98381f3e4872493Nick Pelly      m_pInput_pmem[i].fd = -1;
2101826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#ifdef USE_ION
2102826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      m_pInput_ion[i].ion_device_fd =-1;
2103826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      m_pInput_ion[i].fd_ion_data.fd =-1;
2104826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      m_pInput_ion[i].ion_alloc_data.handle=NULL;
2105826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#endif
210647e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
210747e37c4428509524ee576920a98381f3e4872493Nick Pelly
210847e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
210947e37c4428509524ee576920a98381f3e4872493Nick Pelly
211047e37c4428509524ee576920a98381f3e4872493Nick Pelly  for(i=0; i< m_sInPortDef.nBufferCountActual; i++)
211147e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
211247e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(BITMASK_ABSENT(&m_inp_bm_count,i))
211347e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
211447e37c4428509524ee576920a98381f3e4872493Nick Pelly      break;
211547e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
211647e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
211747e37c4428509524ee576920a98381f3e4872493Nick Pelly
211847e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(i < m_sInPortDef.nBufferCountActual)
211947e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
212047e37c4428509524ee576920a98381f3e4872493Nick Pelly
212147e37c4428509524ee576920a98381f3e4872493Nick Pelly    *bufferHdr = (m_inp_mem_ptr + i);
212247e37c4428509524ee576920a98381f3e4872493Nick Pelly    BITMASK_SET(&m_inp_bm_count,i);
212347e37c4428509524ee576920a98381f3e4872493Nick Pelly
212447e37c4428509524ee576920a98381f3e4872493Nick Pelly    (*bufferHdr)->pBuffer           = (OMX_U8 *)buffer;
212547e37c4428509524ee576920a98381f3e4872493Nick Pelly    (*bufferHdr)->nSize             = sizeof(OMX_BUFFERHEADERTYPE);
212647e37c4428509524ee576920a98381f3e4872493Nick Pelly    (*bufferHdr)->nVersion.nVersion = OMX_SPEC_VERSION;
212747e37c4428509524ee576920a98381f3e4872493Nick Pelly    (*bufferHdr)->nAllocLen         = m_sInPortDef.nBufferSize;
212847e37c4428509524ee576920a98381f3e4872493Nick Pelly    (*bufferHdr)->pAppPrivate       = appData;
212947e37c4428509524ee576920a98381f3e4872493Nick Pelly    (*bufferHdr)->nInputPortIndex   = PORT_INDEX_IN;
213047e37c4428509524ee576920a98381f3e4872493Nick Pelly
213147e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(!m_use_input_pmem)
213247e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
2133826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#ifdef USE_ION
2134826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      m_pInput_ion[i].ion_device_fd = alloc_map_ion_memory(m_sInPortDef.nBufferSize,
2135826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev                                      &m_pInput_ion[i].ion_alloc_data,
213663a6c9bcb0bb20a516059e74ec4113b541f5e919Iliyan Malchev                                      &m_pInput_ion[i].fd_ion_data,ION_FLAG_CACHED);
2137826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      if(m_pInput_ion[i].ion_device_fd < 0) {
2138826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        DEBUG_PRINT_ERROR("\nERROR:ION device open() Failed");
2139826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        return OMX_ErrorInsufficientResources;
2140826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      }
2141826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      m_pInput_pmem[i].fd = m_pInput_ion[i].fd_ion_data.fd;
2142826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#else
2143826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      m_pInput_pmem[i].fd = open (MEM_DEVICE,O_RDWR);
214447e37c4428509524ee576920a98381f3e4872493Nick Pelly      if(m_pInput_pmem[i].fd == 0)
214547e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
2146826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        m_pInput_pmem[i].fd = open (MEM_DEVICE,O_RDWR);
214747e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
214847e37c4428509524ee576920a98381f3e4872493Nick Pelly
214947e37c4428509524ee576920a98381f3e4872493Nick Pelly      if(m_pInput_pmem[i] .fd < 0)
215047e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
215130a73034f38ba1cf31de98ce2560109ce6e535a6Nick Pelly        DEBUG_PRINT_ERROR("\nERROR: /dev/pmem_adsp open() Failed");
215247e37c4428509524ee576920a98381f3e4872493Nick Pelly        return OMX_ErrorInsufficientResources;
215347e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
2154826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#endif
215547e37c4428509524ee576920a98381f3e4872493Nick Pelly      m_pInput_pmem[i].size = m_sInPortDef.nBufferSize;
215647e37c4428509524ee576920a98381f3e4872493Nick Pelly      m_pInput_pmem[i].offset = 0;
215747e37c4428509524ee576920a98381f3e4872493Nick Pelly      m_pInput_pmem[i].buffer = (unsigned char *)mmap(NULL,m_pInput_pmem[i].size,PROT_READ|PROT_WRITE,
215847e37c4428509524ee576920a98381f3e4872493Nick Pelly                                                      MAP_SHARED,m_pInput_pmem[i].fd,0);
215947e37c4428509524ee576920a98381f3e4872493Nick Pelly
216047e37c4428509524ee576920a98381f3e4872493Nick Pelly      if(m_pInput_pmem[i].buffer == MAP_FAILED)
216147e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
216247e37c4428509524ee576920a98381f3e4872493Nick Pelly        DEBUG_PRINT_ERROR("\nERROR: mmap() Failed");
2163826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        close(m_pInput_pmem[i].fd);
2164826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#ifdef USE_ION
2165826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        free_ion_memory(&m_pInput_ion[i]);
2166826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#endif
216747e37c4428509524ee576920a98381f3e4872493Nick Pelly        return OMX_ErrorInsufficientResources;
216847e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
216947e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
217047e37c4428509524ee576920a98381f3e4872493Nick Pelly    else
217147e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
217247e37c4428509524ee576920a98381f3e4872493Nick Pelly      OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *pParam = reinterpret_cast<OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *>((*bufferHdr)->pAppPrivate);
217347e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_LOW("Inside qcom_ext with luma:(fd:%d,offset:0x%x)", pParam->pmem_fd, pParam->offset);
217447e37c4428509524ee576920a98381f3e4872493Nick Pelly
217547e37c4428509524ee576920a98381f3e4872493Nick Pelly      if(pParam)
217647e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
217747e37c4428509524ee576920a98381f3e4872493Nick Pelly        m_pInput_pmem[i].fd = pParam->pmem_fd;
217847e37c4428509524ee576920a98381f3e4872493Nick Pelly        m_pInput_pmem[i].offset = pParam->offset;
217947e37c4428509524ee576920a98381f3e4872493Nick Pelly        m_pInput_pmem[i].size = m_sInPortDef.nBufferSize;
218047e37c4428509524ee576920a98381f3e4872493Nick Pelly        m_pInput_pmem[i].buffer = (unsigned char *)buffer;
218147e37c4428509524ee576920a98381f3e4872493Nick Pelly        DEBUG_PRINT_LOW("\n DBG:: pParam->pmem_fd = %u, pParam->offset = %u",
218247e37c4428509524ee576920a98381f3e4872493Nick Pelly            pParam->pmem_fd, pParam->offset);
218347e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
218447e37c4428509524ee576920a98381f3e4872493Nick Pelly      else
218547e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
218647e37c4428509524ee576920a98381f3e4872493Nick Pelly        DEBUG_PRINT_ERROR("ERROR: Invalid AppData given for PMEM i/p UseBuffer case");
218747e37c4428509524ee576920a98381f3e4872493Nick Pelly        return OMX_ErrorBadParameter;
218847e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
218947e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
219047e37c4428509524ee576920a98381f3e4872493Nick Pelly
2191826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    DEBUG_PRINT_LOW("\nuse_inp:: bufhdr = %p, pBuffer = %p, m_pInput_pmem[i].buffer = %p",
219247e37c4428509524ee576920a98381f3e4872493Nick Pelly                (*bufferHdr), (*bufferHdr)->pBuffer, m_pInput_pmem[i].buffer);
2193826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    if( dev_use_buf(&m_pInput_pmem[i],PORT_INDEX_IN,i) != true)
219447e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
219547e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_ERROR("\nERROR: dev_use_buf() Failed for i/p buf");
219647e37c4428509524ee576920a98381f3e4872493Nick Pelly      return OMX_ErrorInsufficientResources;
219747e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
219847e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
219947e37c4428509524ee576920a98381f3e4872493Nick Pelly  else
220047e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
220147e37c4428509524ee576920a98381f3e4872493Nick Pelly    DEBUG_PRINT_ERROR("\nERROR: All buffers are already used, invalid use_buf call for "
220247e37c4428509524ee576920a98381f3e4872493Nick Pelly                      "index = %u", i);
220347e37c4428509524ee576920a98381f3e4872493Nick Pelly    eRet = OMX_ErrorInsufficientResources;
220447e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
220547e37c4428509524ee576920a98381f3e4872493Nick Pelly
220647e37c4428509524ee576920a98381f3e4872493Nick Pelly  return eRet;
220747e37c4428509524ee576920a98381f3e4872493Nick Pelly}
220847e37c4428509524ee576920a98381f3e4872493Nick Pelly
220947e37c4428509524ee576920a98381f3e4872493Nick Pelly
221047e37c4428509524ee576920a98381f3e4872493Nick Pelly
221147e37c4428509524ee576920a98381f3e4872493Nick Pelly/* ======================================================================
221247e37c4428509524ee576920a98381f3e4872493Nick PellyFUNCTION
221347e37c4428509524ee576920a98381f3e4872493Nick Pelly  omx_video::UseOutputBuffer
221447e37c4428509524ee576920a98381f3e4872493Nick Pelly
221547e37c4428509524ee576920a98381f3e4872493Nick PellyDESCRIPTION
221647e37c4428509524ee576920a98381f3e4872493Nick Pelly  Helper function for Use buffer in the input pin
221747e37c4428509524ee576920a98381f3e4872493Nick Pelly
221847e37c4428509524ee576920a98381f3e4872493Nick PellyPARAMETERS
221947e37c4428509524ee576920a98381f3e4872493Nick Pelly  None.
222047e37c4428509524ee576920a98381f3e4872493Nick Pelly
222147e37c4428509524ee576920a98381f3e4872493Nick PellyRETURN VALUE
222247e37c4428509524ee576920a98381f3e4872493Nick Pelly  true/false
222347e37c4428509524ee576920a98381f3e4872493Nick Pelly
222447e37c4428509524ee576920a98381f3e4872493Nick Pelly========================================================================== */
222547e37c4428509524ee576920a98381f3e4872493Nick PellyOMX_ERRORTYPE  omx_video::use_output_buffer(
222647e37c4428509524ee576920a98381f3e4872493Nick Pelly                                           OMX_IN OMX_HANDLETYPE            hComp,
222747e37c4428509524ee576920a98381f3e4872493Nick Pelly                                           OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr,
222847e37c4428509524ee576920a98381f3e4872493Nick Pelly                                           OMX_IN OMX_U32                   port,
222947e37c4428509524ee576920a98381f3e4872493Nick Pelly                                           OMX_IN OMX_PTR                   appData,
223047e37c4428509524ee576920a98381f3e4872493Nick Pelly                                           OMX_IN OMX_U32                   bytes,
223147e37c4428509524ee576920a98381f3e4872493Nick Pelly                                           OMX_IN OMX_U8*                   buffer)
223247e37c4428509524ee576920a98381f3e4872493Nick Pelly{
223347e37c4428509524ee576920a98381f3e4872493Nick Pelly  OMX_ERRORTYPE eRet = OMX_ErrorNone;
223447e37c4428509524ee576920a98381f3e4872493Nick Pelly  OMX_BUFFERHEADERTYPE       *bufHdr= NULL; // buffer header
223547e37c4428509524ee576920a98381f3e4872493Nick Pelly  unsigned                         i= 0; // Temporary counter
223647e37c4428509524ee576920a98381f3e4872493Nick Pelly  unsigned char *buf_addr = NULL;
223747e37c4428509524ee576920a98381f3e4872493Nick Pelly
223847e37c4428509524ee576920a98381f3e4872493Nick Pelly  DEBUG_PRINT_HIGH("\n Inside use_output_buffer()");
22397783f07680c4e868295efbd0cf55a1622a106522Deva Ramasubramanian  if(bytes != m_sOutPortDef.nBufferSize || secure_session)
224047e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
224147e37c4428509524ee576920a98381f3e4872493Nick Pelly    DEBUG_PRINT_ERROR("\nERROR: use_output_buffer: Size Mismatch!! "
224247e37c4428509524ee576920a98381f3e4872493Nick Pelly                      "bytes[%d] != Port.nBufferSize[%d]", bytes, m_sOutPortDef.nBufferSize);
224347e37c4428509524ee576920a98381f3e4872493Nick Pelly    return OMX_ErrorBadParameter;
224447e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
224547e37c4428509524ee576920a98381f3e4872493Nick Pelly
224647e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(!m_out_mem_ptr)
224747e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
224847e37c4428509524ee576920a98381f3e4872493Nick Pelly    output_use_buffer = true;
224947e37c4428509524ee576920a98381f3e4872493Nick Pelly    int nBufHdrSize        = 0;
225047e37c4428509524ee576920a98381f3e4872493Nick Pelly
225147e37c4428509524ee576920a98381f3e4872493Nick Pelly    DEBUG_PRINT_LOW("Allocating First Output Buffer(%d)\n",m_sOutPortDef.nBufferCountActual);
225247e37c4428509524ee576920a98381f3e4872493Nick Pelly    nBufHdrSize        = m_sOutPortDef.nBufferCountActual * sizeof(OMX_BUFFERHEADERTYPE);
225347e37c4428509524ee576920a98381f3e4872493Nick Pelly    /*
225447e37c4428509524ee576920a98381f3e4872493Nick Pelly     * Memory for output side involves the following:
225547e37c4428509524ee576920a98381f3e4872493Nick Pelly     * 1. Array of Buffer Headers
225647e37c4428509524ee576920a98381f3e4872493Nick Pelly     * 2. Bitmask array to hold the buffer allocation details
225747e37c4428509524ee576920a98381f3e4872493Nick Pelly     * In order to minimize the memory management entire allocation
225847e37c4428509524ee576920a98381f3e4872493Nick Pelly     * is done in one step.
225947e37c4428509524ee576920a98381f3e4872493Nick Pelly     */
226047e37c4428509524ee576920a98381f3e4872493Nick Pelly    //OMX Buffer header
226147e37c4428509524ee576920a98381f3e4872493Nick Pelly    m_out_mem_ptr = (OMX_BUFFERHEADERTYPE  *)calloc(nBufHdrSize,1);
226247e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(m_out_mem_ptr == NULL)
226347e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
226447e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_ERROR("\nERROR: calloc() Failed for m_out_mem_ptr");
226547e37c4428509524ee576920a98381f3e4872493Nick Pelly      return OMX_ErrorInsufficientResources;
226647e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
226747e37c4428509524ee576920a98381f3e4872493Nick Pelly
226847e37c4428509524ee576920a98381f3e4872493Nick Pelly    m_pOutput_pmem = (struct pmem *) calloc(sizeof (struct pmem), m_sOutPortDef.nBufferCountActual);
226947e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(m_pOutput_pmem == NULL)
227047e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
227147e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_ERROR("\nERROR: calloc() Failed for m_pOutput_pmem");
227247e37c4428509524ee576920a98381f3e4872493Nick Pelly      return OMX_ErrorInsufficientResources;
227347e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
2274826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#ifdef USE_ION
2275826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    m_pOutput_ion = (struct venc_ion *) calloc(sizeof (struct venc_ion), m_sOutPortDef.nBufferCountActual);
2276826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    if(m_pOutput_ion == NULL)
2277826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    {
2278826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      DEBUG_PRINT_ERROR("\nERROR: calloc() Failed for m_pOutput_ion");
2279826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      return OMX_ErrorInsufficientResources;
2280826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    }
2281826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#endif
228247e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(m_out_mem_ptr)
228347e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
228447e37c4428509524ee576920a98381f3e4872493Nick Pelly      bufHdr          =  m_out_mem_ptr;
228547e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_LOW("Memory Allocation Succeeded for OUT port%p\n",m_out_mem_ptr);
228647e37c4428509524ee576920a98381f3e4872493Nick Pelly      // Settting the entire storage nicely
228747e37c4428509524ee576920a98381f3e4872493Nick Pelly      for(i=0; i < m_sOutPortDef.nBufferCountActual ; i++)
228847e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
228947e37c4428509524ee576920a98381f3e4872493Nick Pelly        bufHdr->nSize              = sizeof(OMX_BUFFERHEADERTYPE);
229047e37c4428509524ee576920a98381f3e4872493Nick Pelly        bufHdr->nVersion.nVersion  = OMX_SPEC_VERSION;
229147e37c4428509524ee576920a98381f3e4872493Nick Pelly        bufHdr->nAllocLen          = bytes;
229247e37c4428509524ee576920a98381f3e4872493Nick Pelly        bufHdr->nFilledLen         = 0;
229347e37c4428509524ee576920a98381f3e4872493Nick Pelly        bufHdr->pAppPrivate        = appData;
229447e37c4428509524ee576920a98381f3e4872493Nick Pelly        bufHdr->nOutputPortIndex   = PORT_INDEX_OUT;
229547e37c4428509524ee576920a98381f3e4872493Nick Pelly        bufHdr->pBuffer            = NULL;
229647e37c4428509524ee576920a98381f3e4872493Nick Pelly        bufHdr++;
229747e37c4428509524ee576920a98381f3e4872493Nick Pelly        m_pOutput_pmem[i].fd = -1;
2298826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#ifdef USE_ION
2299826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        m_pOutput_ion[i].ion_device_fd =-1;
2300826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        m_pOutput_ion[i].fd_ion_data.fd=-1;
2301826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        m_pOutput_ion[i].ion_alloc_data.handle =NULL;
2302826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#endif
230347e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
230447e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
230547e37c4428509524ee576920a98381f3e4872493Nick Pelly    else
230647e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
230747e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_ERROR("ERROR: Output buf mem alloc failed[0x%x]\n",m_out_mem_ptr);
230847e37c4428509524ee576920a98381f3e4872493Nick Pelly      eRet =  OMX_ErrorInsufficientResources;
230947e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
231047e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
231147e37c4428509524ee576920a98381f3e4872493Nick Pelly
231247e37c4428509524ee576920a98381f3e4872493Nick Pelly  for(i=0; i< m_sOutPortDef.nBufferCountActual; i++)
231347e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
231447e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(BITMASK_ABSENT(&m_out_bm_count,i))
231547e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
231647e37c4428509524ee576920a98381f3e4872493Nick Pelly      break;
231747e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
231847e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
231947e37c4428509524ee576920a98381f3e4872493Nick Pelly
232047e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(eRet == OMX_ErrorNone)
232147e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
232247e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(i < m_sOutPortDef.nBufferCountActual)
232347e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
232447e37c4428509524ee576920a98381f3e4872493Nick Pelly      *bufferHdr = (m_out_mem_ptr + i );
232547e37c4428509524ee576920a98381f3e4872493Nick Pelly      (*bufferHdr)->pBuffer = (OMX_U8 *)buffer;
2326826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev	  (*bufferHdr)->pAppPrivate = appData;
232747e37c4428509524ee576920a98381f3e4872493Nick Pelly      BITMASK_SET(&m_out_bm_count,i);
232847e37c4428509524ee576920a98381f3e4872493Nick Pelly
232947e37c4428509524ee576920a98381f3e4872493Nick Pelly      if(!m_use_output_pmem)
233047e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
2331826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#ifdef USE_ION
2332826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        m_pOutput_ion[i].ion_device_fd = alloc_map_ion_memory(
2333826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev                                         m_sOutPortDef.nBufferSize,
2334826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev                                         &m_pOutput_ion[i].ion_alloc_data,
233563a6c9bcb0bb20a516059e74ec4113b541f5e919Iliyan Malchev                                         &m_pOutput_ion[i].fd_ion_data,ION_FLAG_CACHED);
2336826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      if(m_pOutput_ion[i].ion_device_fd < 0) {
2337826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        DEBUG_PRINT_ERROR("\nERROR:ION device open() Failed");
2338826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        return OMX_ErrorInsufficientResources;
2339826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      }
2340826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      m_pOutput_pmem[i].fd = m_pOutput_ion[i].fd_ion_data.fd;
2341826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#else
2342826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        m_pOutput_pmem[i].fd = open (MEM_DEVICE,O_RDWR);
234347e37c4428509524ee576920a98381f3e4872493Nick Pelly
234447e37c4428509524ee576920a98381f3e4872493Nick Pelly        if(m_pOutput_pmem[i].fd == 0)
234547e37c4428509524ee576920a98381f3e4872493Nick Pelly        {
2346826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev          m_pOutput_pmem[i].fd = open (MEM_DEVICE,O_RDWR);
234747e37c4428509524ee576920a98381f3e4872493Nick Pelly        }
234847e37c4428509524ee576920a98381f3e4872493Nick Pelly
234947e37c4428509524ee576920a98381f3e4872493Nick Pelly        if(m_pOutput_pmem[i].fd < 0)
235047e37c4428509524ee576920a98381f3e4872493Nick Pelly        {
235130a73034f38ba1cf31de98ce2560109ce6e535a6Nick Pelly          DEBUG_PRINT_ERROR("\nERROR: /dev/pmem_adsp open() Failed");
235247e37c4428509524ee576920a98381f3e4872493Nick Pelly          return OMX_ErrorInsufficientResources;
235347e37c4428509524ee576920a98381f3e4872493Nick Pelly        }
2354826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#endif
235547e37c4428509524ee576920a98381f3e4872493Nick Pelly        m_pOutput_pmem[i].size = m_sOutPortDef.nBufferSize;
235647e37c4428509524ee576920a98381f3e4872493Nick Pelly        m_pOutput_pmem[i].offset = 0;
235747e37c4428509524ee576920a98381f3e4872493Nick Pelly        m_pOutput_pmem[i].buffer = (unsigned char *)mmap(NULL,m_pOutput_pmem[i].size,PROT_READ|PROT_WRITE,
235847e37c4428509524ee576920a98381f3e4872493Nick Pelly                                                         MAP_SHARED,m_pOutput_pmem[i].fd,0);
235947e37c4428509524ee576920a98381f3e4872493Nick Pelly        if(m_pOutput_pmem[i].buffer == MAP_FAILED)
236047e37c4428509524ee576920a98381f3e4872493Nick Pelly        {
236147e37c4428509524ee576920a98381f3e4872493Nick Pelly          DEBUG_PRINT_ERROR("\nERROR: mmap() Failed");
2362826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev          close(m_pOutput_pmem[i].fd);
2363826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#ifdef USE_ION
2364826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev          free_ion_memory(&m_pOutput_ion[i]);
2365826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#endif
236647e37c4428509524ee576920a98381f3e4872493Nick Pelly          return OMX_ErrorInsufficientResources;
236747e37c4428509524ee576920a98381f3e4872493Nick Pelly        }
236847e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
236947e37c4428509524ee576920a98381f3e4872493Nick Pelly      else
237047e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
237147e37c4428509524ee576920a98381f3e4872493Nick Pelly        OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *pParam = reinterpret_cast<OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO*>((*bufferHdr)->pAppPrivate);
237247e37c4428509524ee576920a98381f3e4872493Nick Pelly        DEBUG_PRINT_LOW("Inside qcom_ext pParam:0x%x )", pParam);
237347e37c4428509524ee576920a98381f3e4872493Nick Pelly
237447e37c4428509524ee576920a98381f3e4872493Nick Pelly        if(pParam)
237547e37c4428509524ee576920a98381f3e4872493Nick Pelly        {
237647e37c4428509524ee576920a98381f3e4872493Nick Pelly          DEBUG_PRINT_LOW("Inside qcom_ext with luma:(fd:%d,offset:0x%x)", pParam->pmem_fd, pParam->offset);
237747e37c4428509524ee576920a98381f3e4872493Nick Pelly          m_pOutput_pmem[i].fd = pParam->pmem_fd;
237847e37c4428509524ee576920a98381f3e4872493Nick Pelly          m_pOutput_pmem[i].offset = pParam->offset;
237947e37c4428509524ee576920a98381f3e4872493Nick Pelly          m_pOutput_pmem[i].size = m_sOutPortDef.nBufferSize;
238047e37c4428509524ee576920a98381f3e4872493Nick Pelly          m_pOutput_pmem[i].buffer = (unsigned char *)buffer;
238147e37c4428509524ee576920a98381f3e4872493Nick Pelly        }
238247e37c4428509524ee576920a98381f3e4872493Nick Pelly        else
238347e37c4428509524ee576920a98381f3e4872493Nick Pelly        {
238447e37c4428509524ee576920a98381f3e4872493Nick Pelly          DEBUG_PRINT_ERROR("ERROR: Invalid AppData given for PMEM o/p UseBuffer case");
238547e37c4428509524ee576920a98381f3e4872493Nick Pelly          return OMX_ErrorBadParameter;
238647e37c4428509524ee576920a98381f3e4872493Nick Pelly        }
238747e37c4428509524ee576920a98381f3e4872493Nick Pelly        buf_addr = (unsigned char *)buffer;
238847e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
238947e37c4428509524ee576920a98381f3e4872493Nick Pelly
239047e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_LOW("\n use_out:: bufhdr = %p, pBuffer = %p, m_pOutput_pmem[i].buffer = %p",
239147e37c4428509524ee576920a98381f3e4872493Nick Pelly                (*bufferHdr), (*bufferHdr)->pBuffer, m_pOutput_pmem[i].buffer);
2392826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      if(dev_use_buf(&m_pOutput_pmem[i],PORT_INDEX_OUT,i) != true)
239347e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
239447e37c4428509524ee576920a98381f3e4872493Nick Pelly        DEBUG_PRINT_ERROR("ERROR: dev_use_buf Failed for o/p buf");
239547e37c4428509524ee576920a98381f3e4872493Nick Pelly        return OMX_ErrorInsufficientResources;
239647e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
239747e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
239847e37c4428509524ee576920a98381f3e4872493Nick Pelly    else
239947e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
240047e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_ERROR("ERROR: All o/p Buffers have been Used, invalid use_buf call for "
240147e37c4428509524ee576920a98381f3e4872493Nick Pelly                      "index = %u", i);
240247e37c4428509524ee576920a98381f3e4872493Nick Pelly      eRet = OMX_ErrorInsufficientResources;
240347e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
240447e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
240547e37c4428509524ee576920a98381f3e4872493Nick Pelly  return eRet;
240647e37c4428509524ee576920a98381f3e4872493Nick Pelly}
240747e37c4428509524ee576920a98381f3e4872493Nick Pelly
240847e37c4428509524ee576920a98381f3e4872493Nick Pelly
240947e37c4428509524ee576920a98381f3e4872493Nick Pelly/* ======================================================================
241047e37c4428509524ee576920a98381f3e4872493Nick PellyFUNCTION
241147e37c4428509524ee576920a98381f3e4872493Nick Pelly  omx_video::UseBuffer
241247e37c4428509524ee576920a98381f3e4872493Nick Pelly
241347e37c4428509524ee576920a98381f3e4872493Nick PellyDESCRIPTION
241447e37c4428509524ee576920a98381f3e4872493Nick Pelly  OMX Use Buffer method implementation.
241547e37c4428509524ee576920a98381f3e4872493Nick Pelly
241647e37c4428509524ee576920a98381f3e4872493Nick PellyPARAMETERS
241747e37c4428509524ee576920a98381f3e4872493Nick Pelly  <TBD>.
241847e37c4428509524ee576920a98381f3e4872493Nick Pelly
241947e37c4428509524ee576920a98381f3e4872493Nick PellyRETURN VALUE
242047e37c4428509524ee576920a98381f3e4872493Nick Pelly  OMX Error None , if everything successful.
242147e37c4428509524ee576920a98381f3e4872493Nick Pelly
242247e37c4428509524ee576920a98381f3e4872493Nick Pelly========================================================================== */
242347e37c4428509524ee576920a98381f3e4872493Nick PellyOMX_ERRORTYPE  omx_video::use_buffer(
242447e37c4428509524ee576920a98381f3e4872493Nick Pelly                                    OMX_IN OMX_HANDLETYPE            hComp,
242547e37c4428509524ee576920a98381f3e4872493Nick Pelly                                    OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr,
242647e37c4428509524ee576920a98381f3e4872493Nick Pelly                                    OMX_IN OMX_U32                   port,
242747e37c4428509524ee576920a98381f3e4872493Nick Pelly                                    OMX_IN OMX_PTR                   appData,
242847e37c4428509524ee576920a98381f3e4872493Nick Pelly                                    OMX_IN OMX_U32                   bytes,
242947e37c4428509524ee576920a98381f3e4872493Nick Pelly                                    OMX_IN OMX_U8*                   buffer)
243047e37c4428509524ee576920a98381f3e4872493Nick Pelly{
243147e37c4428509524ee576920a98381f3e4872493Nick Pelly  OMX_ERRORTYPE eRet = OMX_ErrorNone;
243247e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(m_state == OMX_StateInvalid)
243347e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
243447e37c4428509524ee576920a98381f3e4872493Nick Pelly    DEBUG_PRINT_ERROR("ERROR: Use Buffer in Invalid State\n");
243547e37c4428509524ee576920a98381f3e4872493Nick Pelly    return OMX_ErrorInvalidState;
243647e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
243747e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(port == PORT_INDEX_IN)
243847e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
243947e37c4428509524ee576920a98381f3e4872493Nick Pelly    eRet = use_input_buffer(hComp,bufferHdr,port,appData,bytes,buffer);
244047e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
244147e37c4428509524ee576920a98381f3e4872493Nick Pelly  else if(port == PORT_INDEX_OUT)
244247e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
244347e37c4428509524ee576920a98381f3e4872493Nick Pelly    eRet = use_output_buffer(hComp,bufferHdr,port,appData,bytes,buffer);
244447e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
244547e37c4428509524ee576920a98381f3e4872493Nick Pelly  else
244647e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
244747e37c4428509524ee576920a98381f3e4872493Nick Pelly    DEBUG_PRINT_ERROR("ERROR: Invalid Port Index received %d\n",(int)port);
244847e37c4428509524ee576920a98381f3e4872493Nick Pelly    eRet = OMX_ErrorBadPortIndex;
244947e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
245047e37c4428509524ee576920a98381f3e4872493Nick Pelly
245147e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(eRet == OMX_ErrorNone)
245247e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
245347e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(allocate_done())
245447e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
245547e37c4428509524ee576920a98381f3e4872493Nick Pelly      if(BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING))
245647e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
245747e37c4428509524ee576920a98381f3e4872493Nick Pelly        // Send the callback now
245847e37c4428509524ee576920a98381f3e4872493Nick Pelly        BITMASK_CLEAR((&m_flags),OMX_COMPONENT_IDLE_PENDING);
245947e37c4428509524ee576920a98381f3e4872493Nick Pelly        post_event(OMX_CommandStateSet,OMX_StateIdle,
246047e37c4428509524ee576920a98381f3e4872493Nick Pelly                   OMX_COMPONENT_GENERATE_EVENT);
246147e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
246247e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
246347e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(port == PORT_INDEX_IN && m_sInPortDef.bPopulated)
246447e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
246547e37c4428509524ee576920a98381f3e4872493Nick Pelly      if(BITMASK_PRESENT(&m_flags,OMX_COMPONENT_INPUT_ENABLE_PENDING))
246647e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
246747e37c4428509524ee576920a98381f3e4872493Nick Pelly        BITMASK_CLEAR((&m_flags),OMX_COMPONENT_INPUT_ENABLE_PENDING);
246847e37c4428509524ee576920a98381f3e4872493Nick Pelly        post_event(OMX_CommandPortEnable,
246947e37c4428509524ee576920a98381f3e4872493Nick Pelly                   PORT_INDEX_IN,
247047e37c4428509524ee576920a98381f3e4872493Nick Pelly                   OMX_COMPONENT_GENERATE_EVENT);
247147e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
247247e37c4428509524ee576920a98381f3e4872493Nick Pelly
247347e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
247447e37c4428509524ee576920a98381f3e4872493Nick Pelly    else if(port == PORT_INDEX_OUT && m_sOutPortDef.bPopulated)
247547e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
247647e37c4428509524ee576920a98381f3e4872493Nick Pelly      if(BITMASK_PRESENT(&m_flags,OMX_COMPONENT_OUTPUT_ENABLE_PENDING))
247747e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
247847e37c4428509524ee576920a98381f3e4872493Nick Pelly        BITMASK_CLEAR((&m_flags),OMX_COMPONENT_OUTPUT_ENABLE_PENDING);
247947e37c4428509524ee576920a98381f3e4872493Nick Pelly        post_event(OMX_CommandPortEnable,
248047e37c4428509524ee576920a98381f3e4872493Nick Pelly                   PORT_INDEX_OUT,
248147e37c4428509524ee576920a98381f3e4872493Nick Pelly                   OMX_COMPONENT_GENERATE_EVENT);
248247e37c4428509524ee576920a98381f3e4872493Nick Pelly        m_event_port_settings_sent = false;
248347e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
248447e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
248547e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
248647e37c4428509524ee576920a98381f3e4872493Nick Pelly  return eRet;
248747e37c4428509524ee576920a98381f3e4872493Nick Pelly}
248847e37c4428509524ee576920a98381f3e4872493Nick Pelly
248947e37c4428509524ee576920a98381f3e4872493Nick PellyOMX_ERRORTYPE omx_video::free_input_buffer(OMX_BUFFERHEADERTYPE *bufferHdr)
249047e37c4428509524ee576920a98381f3e4872493Nick Pelly{
249147e37c4428509524ee576920a98381f3e4872493Nick Pelly  unsigned int index = 0;
249247e37c4428509524ee576920a98381f3e4872493Nick Pelly  OMX_U8 *temp_buff ;
249347e37c4428509524ee576920a98381f3e4872493Nick Pelly
249447e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(bufferHdr == NULL || m_inp_mem_ptr == NULL)
249547e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
249647e37c4428509524ee576920a98381f3e4872493Nick Pelly    DEBUG_PRINT_ERROR("ERROR: free_input: Invalid bufferHdr[%p] or m_inp_mem_ptr[%p]",
249747e37c4428509524ee576920a98381f3e4872493Nick Pelly      bufferHdr, m_inp_mem_ptr);
249847e37c4428509524ee576920a98381f3e4872493Nick Pelly    return OMX_ErrorBadParameter;
249947e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
250047e37c4428509524ee576920a98381f3e4872493Nick Pelly
25017eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  index = bufferHdr - ((!mUseProxyColorFormat)?m_inp_mem_ptr:meta_buffer_hdr);
2502826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#ifdef _ANDROID_ICS_
2503826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  if(meta_mode_enable)
2504826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  {
2505826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    if(index < m_sInPortDef.nBufferCountActual)
2506826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    {
2507826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      memset(&meta_buffer_hdr[index], 0, sizeof(meta_buffer_hdr[index]));
2508826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      memset(&meta_buffers[index], 0, sizeof(meta_buffers[index]));
2509826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    }
25107eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    if(!mUseProxyColorFormat)
25117eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      return OMX_ErrorNone;
2512be03db07985878ca3da2edf5341261c6b67accd7Praveen Chavan    else {
25137eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      c2d_conv.close();
2514be03db07985878ca3da2edf5341261c6b67accd7Praveen Chavan      opaque_buffer_hdr[index] = NULL;
2515be03db07985878ca3da2edf5341261c6b67accd7Praveen Chavan    }
2516826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  }
2517826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#endif
25187eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  if(index < m_sInPortDef.nBufferCountActual && !mUseProxyColorFormat &&
2519826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev     dev_free_buf(&m_pInput_pmem[index],PORT_INDEX_IN) != true)
2520826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  {
25217eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    DEBUG_PRINT_LOW("\nERROR: dev_free_buf() Failed for i/p buf");
2522826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  }
252347e37c4428509524ee576920a98381f3e4872493Nick Pelly
252447e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(index < m_sInPortDef.nBufferCountActual && m_pInput_pmem)
252547e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
252647e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(m_pInput_pmem[index].fd > 0 && input_use_buffer == false)
252747e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
252847e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_LOW("\n FreeBuffer:: i/p AllocateBuffer case");
252947e37c4428509524ee576920a98381f3e4872493Nick Pelly      munmap (m_pInput_pmem[index].buffer,m_pInput_pmem[index].size);
253047e37c4428509524ee576920a98381f3e4872493Nick Pelly      close (m_pInput_pmem[index].fd);
2531826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#ifdef USE_ION
2532826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      free_ion_memory(&m_pInput_ion[index]);
2533826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#endif
253447e37c4428509524ee576920a98381f3e4872493Nick Pelly      m_pInput_pmem[index].fd = -1;
253547e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
253647e37c4428509524ee576920a98381f3e4872493Nick Pelly    else if(m_pInput_pmem[index].fd > 0 && (input_use_buffer == true &&
253747e37c4428509524ee576920a98381f3e4872493Nick Pelly      m_use_input_pmem == OMX_FALSE))
253847e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
253947e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_LOW("\n FreeBuffer:: i/p Heap UseBuffer case");
254047e37c4428509524ee576920a98381f3e4872493Nick Pelly      if(dev_free_buf(&m_pInput_pmem[index],PORT_INDEX_IN) != true)
254147e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
254247e37c4428509524ee576920a98381f3e4872493Nick Pelly        DEBUG_PRINT_ERROR("\nERROR: dev_free_buf() Failed for i/p buf");
254347e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
254447e37c4428509524ee576920a98381f3e4872493Nick Pelly      munmap (m_pInput_pmem[index].buffer,m_pInput_pmem[index].size);
254547e37c4428509524ee576920a98381f3e4872493Nick Pelly      close (m_pInput_pmem[index].fd);
2546826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#ifdef USE_ION
2547826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      free_ion_memory(&m_pInput_ion[index]);
2548826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#endif
254947e37c4428509524ee576920a98381f3e4872493Nick Pelly      m_pInput_pmem[index].fd = -1;
255047e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
255147e37c4428509524ee576920a98381f3e4872493Nick Pelly    else
255247e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
25537eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      DEBUG_PRINT_ERROR("\n FreeBuffer:: fd is invalid or i/p PMEM UseBuffer case");
255447e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
255547e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
255647e37c4428509524ee576920a98381f3e4872493Nick Pelly  return OMX_ErrorNone;
255747e37c4428509524ee576920a98381f3e4872493Nick Pelly}
255847e37c4428509524ee576920a98381f3e4872493Nick Pelly
255947e37c4428509524ee576920a98381f3e4872493Nick PellyOMX_ERRORTYPE omx_video::free_output_buffer(OMX_BUFFERHEADERTYPE *bufferHdr)
256047e37c4428509524ee576920a98381f3e4872493Nick Pelly{
256147e37c4428509524ee576920a98381f3e4872493Nick Pelly  unsigned int index = 0;
256247e37c4428509524ee576920a98381f3e4872493Nick Pelly  OMX_U8 *temp_buff ;
256347e37c4428509524ee576920a98381f3e4872493Nick Pelly
256447e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(bufferHdr == NULL || m_out_mem_ptr == NULL)
256547e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
256647e37c4428509524ee576920a98381f3e4872493Nick Pelly    DEBUG_PRINT_ERROR("ERROR: free_output: Invalid bufferHdr[%p] or m_out_mem_ptr[%p]",
256747e37c4428509524ee576920a98381f3e4872493Nick Pelly      bufferHdr, m_out_mem_ptr);
256847e37c4428509524ee576920a98381f3e4872493Nick Pelly    return OMX_ErrorBadParameter;
256947e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
257047e37c4428509524ee576920a98381f3e4872493Nick Pelly  index = bufferHdr - m_out_mem_ptr;
257147e37c4428509524ee576920a98381f3e4872493Nick Pelly
2572826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  if(index < m_sOutPortDef.nBufferCountActual &&
2573826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev     dev_free_buf(&m_pOutput_pmem[index],PORT_INDEX_OUT) != true)
2574826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  {
2575826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    DEBUG_PRINT_ERROR("ERROR: dev_free_buf Failed for o/p buf");
2576826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  }
2577826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev
257847e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(index < m_sOutPortDef.nBufferCountActual && m_pOutput_pmem)
257947e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
258047e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(m_pOutput_pmem[index].fd > 0 && output_use_buffer == false )
258147e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
258247e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_LOW("\n FreeBuffer:: o/p AllocateBuffer case");
25837783f07680c4e868295efbd0cf55a1622a106522Deva Ramasubramanian      if(!secure_session)
25847783f07680c4e868295efbd0cf55a1622a106522Deva Ramasubramanian        munmap (m_pOutput_pmem[index].buffer,m_pOutput_pmem[index].size);
258547e37c4428509524ee576920a98381f3e4872493Nick Pelly      close (m_pOutput_pmem[index].fd);
2586826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#ifdef USE_ION
2587826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      free_ion_memory(&m_pOutput_ion[index]);
2588826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#endif
258947e37c4428509524ee576920a98381f3e4872493Nick Pelly      m_pOutput_pmem[index].fd = -1;
259047e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
259147e37c4428509524ee576920a98381f3e4872493Nick Pelly    else if( m_pOutput_pmem[index].fd > 0 && (output_use_buffer == true
259247e37c4428509524ee576920a98381f3e4872493Nick Pelly      && m_use_output_pmem == OMX_FALSE))
259347e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
259447e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_LOW("\n FreeBuffer:: o/p Heap UseBuffer case");
259547e37c4428509524ee576920a98381f3e4872493Nick Pelly      if(dev_free_buf(&m_pOutput_pmem[index],PORT_INDEX_OUT) != true)
259647e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
259747e37c4428509524ee576920a98381f3e4872493Nick Pelly        DEBUG_PRINT_ERROR("ERROR: dev_free_buf Failed for o/p buf");
259847e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
259947e37c4428509524ee576920a98381f3e4872493Nick Pelly      munmap (m_pOutput_pmem[index].buffer,m_pOutput_pmem[index].size);
260047e37c4428509524ee576920a98381f3e4872493Nick Pelly      close (m_pOutput_pmem[index].fd);
2601826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#ifdef USE_ION
2602826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      free_ion_memory(&m_pOutput_ion[index]);
2603826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#endif
260447e37c4428509524ee576920a98381f3e4872493Nick Pelly      m_pOutput_pmem[index].fd = -1;
260547e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
260647e37c4428509524ee576920a98381f3e4872493Nick Pelly    else
260747e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
260847e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_LOW("\n FreeBuffer:: fd is invalid or o/p PMEM UseBuffer case");
260947e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
261047e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
261147e37c4428509524ee576920a98381f3e4872493Nick Pelly  return OMX_ErrorNone;
261247e37c4428509524ee576920a98381f3e4872493Nick Pelly}
2613826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#ifdef _ANDROID_ICS_
2614826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan MalchevOMX_ERRORTYPE omx_video::allocate_input_meta_buffer(
26157eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George                    OMX_HANDLETYPE       hComp,
2616826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev                    OMX_BUFFERHEADERTYPE **bufferHdr,
2617826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev                    OMX_PTR              appData,
2618826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev                    OMX_U32              bytes)
2619826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev{
2620826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  unsigned index = 0;
2621826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  if(!bufferHdr || bytes != sizeof(encoder_media_buffer_type))
2622826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  {
2623826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    DEBUG_PRINT_ERROR("wrong params allocate_input_meta_buffer Hdr %p len %d",
2624826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev                     bufferHdr,bytes);
2625826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    return OMX_ErrorBadParameter;
2626826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  }
26277eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  if(!m_inp_mem_ptr && !mUseProxyColorFormat)
2628826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    m_inp_mem_ptr = meta_buffer_hdr;
2629826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  for(index = 0;((index < m_sInPortDef.nBufferCountActual) &&
2630826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      meta_buffer_hdr[index].pBuffer); index++);
2631826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  if(index == m_sInPortDef.nBufferCountActual)
2632826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  {
2633826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    DEBUG_PRINT_ERROR("All buffers are allocated input_meta_buffer");
2634826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    return OMX_ErrorBadParameter;
2635826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  }
26367eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  if(mUseProxyColorFormat){
26377eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    if(opaque_buffer_hdr[index]){
26387eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      DEBUG_PRINT_ERROR("All buffers are allocated opaque_buffer_hdr");
26397eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      return OMX_ErrorBadParameter;
26407eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    }
26417eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    if(allocate_input_buffer(hComp,&opaque_buffer_hdr[index],
26427eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George       PORT_INDEX_IN,appData,m_sInPortDef.nBufferSize) != OMX_ErrorNone) {
26437eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      DEBUG_PRINT_ERROR("All buffers are allocated opaque_buffer_hdr");
26447eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      return OMX_ErrorBadParameter;
26457eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    }
26467eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  }
2647826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  BITMASK_SET(&m_inp_bm_count,index);
2648826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  *bufferHdr = &meta_buffer_hdr[index];
2649826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  memset(&meta_buffer_hdr[index], 0, sizeof(meta_buffer_hdr[index]));
2650826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  meta_buffer_hdr[index].nSize = sizeof(meta_buffer_hdr[index]);
2651826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  meta_buffer_hdr[index].nAllocLen = bytes;
2652826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  meta_buffer_hdr[index].nVersion.nVersion = OMX_SPEC_VERSION;
2653826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  meta_buffer_hdr[index].nInputPortIndex = PORT_INDEX_IN;
2654826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  meta_buffer_hdr[index].pBuffer = (OMX_U8*)&meta_buffers[index];
2655826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  meta_buffer_hdr[index].pAppPrivate = appData;
26567eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  if(mUseProxyColorFormat) {
26577eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    m_opq_pmem_q.insert_entry((unsigned int)opaque_buffer_hdr[index],0,0);
26587eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    DEBUG_PRINT_HIGH("\n opaque_buffer_hdr insert %p", opaque_buffer_hdr[index]);
26597eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  }
2660826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  return OMX_ErrorNone;
2661826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev}
2662826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#endif
266347e37c4428509524ee576920a98381f3e4872493Nick Pelly/* ======================================================================
266447e37c4428509524ee576920a98381f3e4872493Nick PellyFUNCTION
266547e37c4428509524ee576920a98381f3e4872493Nick Pelly  omx_venc::AllocateInputBuffer
266647e37c4428509524ee576920a98381f3e4872493Nick Pelly
266747e37c4428509524ee576920a98381f3e4872493Nick PellyDESCRIPTION
266847e37c4428509524ee576920a98381f3e4872493Nick Pelly  Helper function for allocate buffer in the input pin
266947e37c4428509524ee576920a98381f3e4872493Nick Pelly
267047e37c4428509524ee576920a98381f3e4872493Nick PellyPARAMETERS
267147e37c4428509524ee576920a98381f3e4872493Nick Pelly  None.
267247e37c4428509524ee576920a98381f3e4872493Nick Pelly
267347e37c4428509524ee576920a98381f3e4872493Nick PellyRETURN VALUE
267447e37c4428509524ee576920a98381f3e4872493Nick Pelly  true/false
267547e37c4428509524ee576920a98381f3e4872493Nick Pelly
267647e37c4428509524ee576920a98381f3e4872493Nick Pelly========================================================================== */
267747e37c4428509524ee576920a98381f3e4872493Nick PellyOMX_ERRORTYPE  omx_video::allocate_input_buffer(
267847e37c4428509524ee576920a98381f3e4872493Nick Pelly                                               OMX_IN OMX_HANDLETYPE            hComp,
267947e37c4428509524ee576920a98381f3e4872493Nick Pelly                                               OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr,
268047e37c4428509524ee576920a98381f3e4872493Nick Pelly                                               OMX_IN OMX_U32                   port,
268147e37c4428509524ee576920a98381f3e4872493Nick Pelly                                               OMX_IN OMX_PTR                   appData,
268247e37c4428509524ee576920a98381f3e4872493Nick Pelly                                               OMX_IN OMX_U32                   bytes)
268347e37c4428509524ee576920a98381f3e4872493Nick Pelly{
268447e37c4428509524ee576920a98381f3e4872493Nick Pelly
268547e37c4428509524ee576920a98381f3e4872493Nick Pelly  OMX_ERRORTYPE eRet = OMX_ErrorNone;
268647e37c4428509524ee576920a98381f3e4872493Nick Pelly  unsigned   i = 0;
268747e37c4428509524ee576920a98381f3e4872493Nick Pelly
268847e37c4428509524ee576920a98381f3e4872493Nick Pelly  DEBUG_PRINT_HIGH("\n allocate_input_buffer()::");
26897783f07680c4e868295efbd0cf55a1622a106522Deva Ramasubramanian  if(bytes != m_sInPortDef.nBufferSize || secure_session)
269047e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
269147e37c4428509524ee576920a98381f3e4872493Nick Pelly    DEBUG_PRINT_ERROR("\nERROR: Buffer size mismatch error: bytes[%u] != nBufferSize[%u]\n",
269247e37c4428509524ee576920a98381f3e4872493Nick Pelly      bytes, m_sInPortDef.nBufferSize);
269347e37c4428509524ee576920a98381f3e4872493Nick Pelly    return OMX_ErrorBadParameter;
269447e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
269547e37c4428509524ee576920a98381f3e4872493Nick Pelly
269647e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(!m_inp_mem_ptr)
269747e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
2698826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    DEBUG_PRINT_HIGH("%s: size = %d, actual cnt %d", __FUNCTION__,
2699826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        m_sInPortDef.nBufferSize, m_sInPortDef.nBufferCountActual);
270047e37c4428509524ee576920a98381f3e4872493Nick Pelly    m_inp_mem_ptr = (OMX_BUFFERHEADERTYPE*) \
270147e37c4428509524ee576920a98381f3e4872493Nick Pelly                    calloc( (sizeof(OMX_BUFFERHEADERTYPE)), m_sInPortDef.nBufferCountActual);
270247e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(m_inp_mem_ptr == NULL)
270347e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
270447e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_ERROR("\nERROR: calloc() Failed for m_inp_mem_ptr");
270547e37c4428509524ee576920a98381f3e4872493Nick Pelly      return OMX_ErrorInsufficientResources;
270647e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
270747e37c4428509524ee576920a98381f3e4872493Nick Pelly
270847e37c4428509524ee576920a98381f3e4872493Nick Pelly    m_pInput_pmem = (struct pmem *) calloc(sizeof (struct pmem), m_sInPortDef.nBufferCountActual);
270947e37c4428509524ee576920a98381f3e4872493Nick Pelly
271047e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(m_pInput_pmem == NULL)
271147e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
271247e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_ERROR("\nERROR: calloc() Failed for m_pInput_pmem");
271347e37c4428509524ee576920a98381f3e4872493Nick Pelly      return OMX_ErrorInsufficientResources;
271447e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
2715826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#ifdef USE_ION
2716826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    m_pInput_ion = (struct venc_ion *) calloc(sizeof (struct venc_ion), m_sInPortDef.nBufferCountActual);
2717826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    if(m_pInput_ion == NULL)
2718826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    {
2719826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      DEBUG_PRINT_ERROR("\nERROR: calloc() Failed for m_pInput_ion");
2720826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      return OMX_ErrorInsufficientResources;
2721826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    }
2722826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#endif
272347e37c4428509524ee576920a98381f3e4872493Nick Pelly    for(i=0; i< m_sInPortDef.nBufferCountActual; i++)
272447e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
272547e37c4428509524ee576920a98381f3e4872493Nick Pelly      m_pInput_pmem[i].fd = -1;
2726826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#ifdef USE_ION
2727826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      m_pInput_ion[i].ion_device_fd =-1;
2728826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      m_pInput_ion[i].fd_ion_data.fd =-1;
2729826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      m_pInput_ion[i].ion_alloc_data.handle=NULL;
2730826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#endif
273147e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
273247e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
273347e37c4428509524ee576920a98381f3e4872493Nick Pelly
273447e37c4428509524ee576920a98381f3e4872493Nick Pelly  for(i=0; i< m_sInPortDef.nBufferCountActual; i++)
273547e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
273647e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(BITMASK_ABSENT(&m_inp_bm_count,i))
273747e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
273847e37c4428509524ee576920a98381f3e4872493Nick Pelly      break;
273947e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
274047e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
274147e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(i < m_sInPortDef.nBufferCountActual)
274247e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
274347e37c4428509524ee576920a98381f3e4872493Nick Pelly
274447e37c4428509524ee576920a98381f3e4872493Nick Pelly    *bufferHdr = (m_inp_mem_ptr + i);
274547e37c4428509524ee576920a98381f3e4872493Nick Pelly    (*bufferHdr)->nSize             = sizeof(OMX_BUFFERHEADERTYPE);
274647e37c4428509524ee576920a98381f3e4872493Nick Pelly    (*bufferHdr)->nVersion.nVersion = OMX_SPEC_VERSION;
274747e37c4428509524ee576920a98381f3e4872493Nick Pelly    (*bufferHdr)->nAllocLen         = m_sInPortDef.nBufferSize;
274847e37c4428509524ee576920a98381f3e4872493Nick Pelly    (*bufferHdr)->pAppPrivate       = appData;
274947e37c4428509524ee576920a98381f3e4872493Nick Pelly    (*bufferHdr)->nInputPortIndex   = PORT_INDEX_IN;
275047e37c4428509524ee576920a98381f3e4872493Nick Pelly
2751826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#ifdef USE_ION
2752826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    m_pInput_ion[i].ion_device_fd = alloc_map_ion_memory(m_sInPortDef.nBufferSize,
2753826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev                                    &m_pInput_ion[i].ion_alloc_data,
275499faaf7cd04116922fc35ab5c72c023d6b23e8a8Praveen Chavan                                    &m_pInput_ion[i].fd_ion_data,0);
2755826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    if(m_pInput_ion[i].ion_device_fd < 0) {
2756826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      DEBUG_PRINT_ERROR("\nERROR:ION device open() Failed");
2757826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      return OMX_ErrorInsufficientResources;
2758826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    }
2759826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev
2760826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    m_pInput_pmem[i].fd = m_pInput_ion[i].fd_ion_data.fd;
2761826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#else
2762826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    m_pInput_pmem[i].fd = open (MEM_DEVICE,O_RDWR);
276347e37c4428509524ee576920a98381f3e4872493Nick Pelly
276447e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(m_pInput_pmem[i].fd == 0)
276547e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
2766826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      m_pInput_pmem[i].fd = open (MEM_DEVICE,O_RDWR);
276747e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
276847e37c4428509524ee576920a98381f3e4872493Nick Pelly
276947e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(m_pInput_pmem[i].fd < 0)
277047e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
277130a73034f38ba1cf31de98ce2560109ce6e535a6Nick Pelly      DEBUG_PRINT_ERROR("\nERROR: /dev/pmem_adsp open() Failed\n");
277247e37c4428509524ee576920a98381f3e4872493Nick Pelly      return OMX_ErrorInsufficientResources;
277347e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
2774826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#endif
277547e37c4428509524ee576920a98381f3e4872493Nick Pelly    m_pInput_pmem[i].size = m_sInPortDef.nBufferSize;
277647e37c4428509524ee576920a98381f3e4872493Nick Pelly    m_pInput_pmem[i].offset = 0;
277747e37c4428509524ee576920a98381f3e4872493Nick Pelly
277847e37c4428509524ee576920a98381f3e4872493Nick Pelly    m_pInput_pmem[i].buffer = (unsigned char *)mmap(NULL,m_pInput_pmem[i].size,PROT_READ|PROT_WRITE,
277947e37c4428509524ee576920a98381f3e4872493Nick Pelly                                                    MAP_SHARED,m_pInput_pmem[i].fd,0);
278047e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(m_pInput_pmem[i].buffer == MAP_FAILED)
278147e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
2782826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      DEBUG_PRINT_ERROR("\nERROR: mmap FAILED= %d\n", errno);
2783826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      close(m_pInput_pmem[i].fd);
2784826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#ifdef USE_ION
2785826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      free_ion_memory(&m_pInput_ion[i]);
2786826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#endif
278747e37c4428509524ee576920a98381f3e4872493Nick Pelly      return OMX_ErrorInsufficientResources;
278847e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
278947e37c4428509524ee576920a98381f3e4872493Nick Pelly
279047e37c4428509524ee576920a98381f3e4872493Nick Pelly    (*bufferHdr)->pBuffer           = (OMX_U8 *)m_pInput_pmem[i].buffer;
27917eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    DEBUG_PRINT_LOW("\n Virtual address in allocate buffer is %p", m_pInput_pmem[i].buffer);
279247e37c4428509524ee576920a98381f3e4872493Nick Pelly    BITMASK_SET(&m_inp_bm_count,i);
279347e37c4428509524ee576920a98381f3e4872493Nick Pelly    //here change the I/P param here from buf_adr to pmem
27947eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    if(!mUseProxyColorFormat && (dev_use_buf(&m_pInput_pmem[i],PORT_INDEX_IN,i) != true))
279547e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
279647e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_ERROR("\nERROR: dev_use_buf FAILED for i/p buf\n");
279747e37c4428509524ee576920a98381f3e4872493Nick Pelly      return OMX_ErrorInsufficientResources;
279847e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
279947e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
280047e37c4428509524ee576920a98381f3e4872493Nick Pelly  else
280147e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
280247e37c4428509524ee576920a98381f3e4872493Nick Pelly    DEBUG_PRINT_ERROR("\nERROR: All i/p buffers are allocated, invalid allocate buf call"
280347e37c4428509524ee576920a98381f3e4872493Nick Pelly                      "for index [%d]\n", i);
280447e37c4428509524ee576920a98381f3e4872493Nick Pelly    eRet = OMX_ErrorInsufficientResources;
280547e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
280647e37c4428509524ee576920a98381f3e4872493Nick Pelly
280747e37c4428509524ee576920a98381f3e4872493Nick Pelly  return eRet;
280847e37c4428509524ee576920a98381f3e4872493Nick Pelly}
280947e37c4428509524ee576920a98381f3e4872493Nick Pelly
281047e37c4428509524ee576920a98381f3e4872493Nick Pelly
281147e37c4428509524ee576920a98381f3e4872493Nick Pelly/* ======================================================================
281247e37c4428509524ee576920a98381f3e4872493Nick PellyFUNCTION
281347e37c4428509524ee576920a98381f3e4872493Nick Pelly  omx_venc::AllocateOutputBuffer
281447e37c4428509524ee576920a98381f3e4872493Nick Pelly
281547e37c4428509524ee576920a98381f3e4872493Nick PellyDESCRIPTION
281647e37c4428509524ee576920a98381f3e4872493Nick Pelly  Helper fn for AllocateBuffer in the output pin
281747e37c4428509524ee576920a98381f3e4872493Nick Pelly
281847e37c4428509524ee576920a98381f3e4872493Nick PellyPARAMETERS
281947e37c4428509524ee576920a98381f3e4872493Nick Pelly  <TBD>.
282047e37c4428509524ee576920a98381f3e4872493Nick Pelly
282147e37c4428509524ee576920a98381f3e4872493Nick PellyRETURN VALUE
282247e37c4428509524ee576920a98381f3e4872493Nick Pelly  OMX Error None if everything went well.
282347e37c4428509524ee576920a98381f3e4872493Nick Pelly
282447e37c4428509524ee576920a98381f3e4872493Nick Pelly========================================================================== */
282547e37c4428509524ee576920a98381f3e4872493Nick PellyOMX_ERRORTYPE  omx_video::allocate_output_buffer(
282647e37c4428509524ee576920a98381f3e4872493Nick Pelly                                                OMX_IN OMX_HANDLETYPE            hComp,
282747e37c4428509524ee576920a98381f3e4872493Nick Pelly                                                OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr,
282847e37c4428509524ee576920a98381f3e4872493Nick Pelly                                                OMX_IN OMX_U32                   port,
282947e37c4428509524ee576920a98381f3e4872493Nick Pelly                                                OMX_IN OMX_PTR                   appData,
283047e37c4428509524ee576920a98381f3e4872493Nick Pelly                                                OMX_IN OMX_U32                   bytes)
283147e37c4428509524ee576920a98381f3e4872493Nick Pelly{
283247e37c4428509524ee576920a98381f3e4872493Nick Pelly  OMX_ERRORTYPE eRet = OMX_ErrorNone;
283347e37c4428509524ee576920a98381f3e4872493Nick Pelly  OMX_BUFFERHEADERTYPE       *bufHdr= NULL; // buffer header
283447e37c4428509524ee576920a98381f3e4872493Nick Pelly  unsigned                         i= 0; // Temporary counter
2835826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev
283647e37c4428509524ee576920a98381f3e4872493Nick Pelly  DEBUG_PRINT_HIGH("\n allocate_output_buffer()::");
283747e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(!m_out_mem_ptr)
283847e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
283947e37c4428509524ee576920a98381f3e4872493Nick Pelly    int nBufHdrSize        = 0;
2840826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    DEBUG_PRINT_HIGH("%s: size = %d, actual cnt %d", __FUNCTION__,
2841826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        m_sOutPortDef.nBufferSize, m_sOutPortDef.nBufferCountActual);
284247e37c4428509524ee576920a98381f3e4872493Nick Pelly    nBufHdrSize        = m_sOutPortDef.nBufferCountActual * sizeof(OMX_BUFFERHEADERTYPE);
284347e37c4428509524ee576920a98381f3e4872493Nick Pelly
284447e37c4428509524ee576920a98381f3e4872493Nick Pelly    /*
284547e37c4428509524ee576920a98381f3e4872493Nick Pelly     * Memory for output side involves the following:
284647e37c4428509524ee576920a98381f3e4872493Nick Pelly     * 1. Array of Buffer Headers
284747e37c4428509524ee576920a98381f3e4872493Nick Pelly     * 2. Bitmask array to hold the buffer allocation details
284847e37c4428509524ee576920a98381f3e4872493Nick Pelly     * In order to minimize the memory management entire allocation
284947e37c4428509524ee576920a98381f3e4872493Nick Pelly     * is done in one step.
285047e37c4428509524ee576920a98381f3e4872493Nick Pelly     */
285147e37c4428509524ee576920a98381f3e4872493Nick Pelly    m_out_mem_ptr = (OMX_BUFFERHEADERTYPE  *)calloc(nBufHdrSize,1);
285247e37c4428509524ee576920a98381f3e4872493Nick Pelly
2853826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#ifdef USE_ION
2854826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    m_pOutput_ion = (struct venc_ion *) calloc(sizeof (struct venc_ion), m_sOutPortDef.nBufferCountActual);
2855826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    if(m_pOutput_ion == NULL)
2856826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    {
2857826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      DEBUG_PRINT_ERROR("\nERROR: calloc() Failed for m_pOutput_ion");
2858826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      return OMX_ErrorInsufficientResources;
2859826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    }
2860826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#endif
286147e37c4428509524ee576920a98381f3e4872493Nick Pelly    m_pOutput_pmem = (struct pmem *) calloc(sizeof(struct pmem), m_sOutPortDef.nBufferCountActual);
2862826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    if(m_pOutput_pmem == NULL)
2863826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    {
2864826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      DEBUG_PRINT_ERROR("\nERROR: calloc() Failed for m_pOutput_pmem");
2865826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      return OMX_ErrorInsufficientResources;
2866826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    }
286747e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(m_out_mem_ptr && m_pOutput_pmem)
286847e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
286947e37c4428509524ee576920a98381f3e4872493Nick Pelly      bufHdr          =  m_out_mem_ptr;
287047e37c4428509524ee576920a98381f3e4872493Nick Pelly
287147e37c4428509524ee576920a98381f3e4872493Nick Pelly      for(i=0; i < m_sOutPortDef.nBufferCountActual ; i++)
287247e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
287347e37c4428509524ee576920a98381f3e4872493Nick Pelly        bufHdr->nSize              = sizeof(OMX_BUFFERHEADERTYPE);
287447e37c4428509524ee576920a98381f3e4872493Nick Pelly        bufHdr->nVersion.nVersion  = OMX_SPEC_VERSION;
287547e37c4428509524ee576920a98381f3e4872493Nick Pelly        // Set the values when we determine the right HxW param
287647e37c4428509524ee576920a98381f3e4872493Nick Pelly        bufHdr->nAllocLen          = bytes;
287747e37c4428509524ee576920a98381f3e4872493Nick Pelly        bufHdr->nFilledLen         = 0;
287847e37c4428509524ee576920a98381f3e4872493Nick Pelly        bufHdr->pAppPrivate        = appData;
287947e37c4428509524ee576920a98381f3e4872493Nick Pelly        bufHdr->nOutputPortIndex   = PORT_INDEX_OUT;
288047e37c4428509524ee576920a98381f3e4872493Nick Pelly        bufHdr->pBuffer            = NULL;
288147e37c4428509524ee576920a98381f3e4872493Nick Pelly        bufHdr++;
288247e37c4428509524ee576920a98381f3e4872493Nick Pelly        m_pOutput_pmem[i].fd = -1;
2883826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#ifdef USE_ION
2884826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        m_pOutput_ion[i].ion_device_fd =-1;
2885826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        m_pOutput_ion[i].fd_ion_data.fd=-1;
2886826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        m_pOutput_ion[i].ion_alloc_data.handle =NULL;
2887826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#endif
288847e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
288947e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
289047e37c4428509524ee576920a98381f3e4872493Nick Pelly    else
289147e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
289247e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_ERROR("ERROR: calloc() failed for m_out_mem_ptr/m_pOutput_pmem");
289347e37c4428509524ee576920a98381f3e4872493Nick Pelly      eRet = OMX_ErrorInsufficientResources;
289447e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
289547e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
289647e37c4428509524ee576920a98381f3e4872493Nick Pelly
289747e37c4428509524ee576920a98381f3e4872493Nick Pelly  DEBUG_PRINT_HIGH("\n actual cnt = %u", m_sOutPortDef.nBufferCountActual);
289847e37c4428509524ee576920a98381f3e4872493Nick Pelly  for(i=0; i< m_sOutPortDef.nBufferCountActual; i++)
289947e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
290047e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(BITMASK_ABSENT(&m_out_bm_count,i))
290147e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
290247e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_LOW("\n Found a Free Output Buffer %d",i);
290347e37c4428509524ee576920a98381f3e4872493Nick Pelly      break;
290447e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
290547e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
290647e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(eRet == OMX_ErrorNone)
290747e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
290847e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(i < m_sOutPortDef.nBufferCountActual)
290947e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
2910826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#ifdef USE_ION
2911826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      m_pOutput_ion[i].ion_device_fd = alloc_map_ion_memory(m_sOutPortDef.nBufferSize,
2912826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev                                       &m_pOutput_ion[i].ion_alloc_data,
291363a6c9bcb0bb20a516059e74ec4113b541f5e919Iliyan Malchev                                       &m_pOutput_ion[i].fd_ion_data,ION_FLAG_CACHED);
2914826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      if(m_pOutput_ion[i].ion_device_fd < 0) {
2915826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        DEBUG_PRINT_ERROR("\nERROR:ION device open() Failed");
2916826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        return OMX_ErrorInsufficientResources;
2917826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      }
2918826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      m_pOutput_pmem[i].fd = m_pOutput_ion[i].fd_ion_data.fd;
2919826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#else
2920826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      m_pOutput_pmem[i].fd = open (MEM_DEVICE,O_RDWR);
292147e37c4428509524ee576920a98381f3e4872493Nick Pelly      if(m_pOutput_pmem[i].fd == 0)
292247e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
2923826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        m_pOutput_pmem[i].fd = open (MEM_DEVICE,O_RDWR);
292447e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
292547e37c4428509524ee576920a98381f3e4872493Nick Pelly
292647e37c4428509524ee576920a98381f3e4872493Nick Pelly      if(m_pOutput_pmem[i].fd < 0)
292747e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
292830a73034f38ba1cf31de98ce2560109ce6e535a6Nick Pelly        DEBUG_PRINT_ERROR("\nERROR: /dev/pmem_adsp open() failed");
292947e37c4428509524ee576920a98381f3e4872493Nick Pelly        return OMX_ErrorInsufficientResources;
293047e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
2931826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#endif
293247e37c4428509524ee576920a98381f3e4872493Nick Pelly      m_pOutput_pmem[i].size = m_sOutPortDef.nBufferSize;
293347e37c4428509524ee576920a98381f3e4872493Nick Pelly      m_pOutput_pmem[i].offset = 0;
29347783f07680c4e868295efbd0cf55a1622a106522Deva Ramasubramanian      if(!secure_session) {
29357783f07680c4e868295efbd0cf55a1622a106522Deva Ramasubramanian          m_pOutput_pmem[i].buffer = (unsigned char *)mmap(NULL,m_pOutput_pmem[i].size,PROT_READ|PROT_WRITE,
29367783f07680c4e868295efbd0cf55a1622a106522Deva Ramasubramanian                  MAP_SHARED,m_pOutput_pmem[i].fd,0);
29377783f07680c4e868295efbd0cf55a1622a106522Deva Ramasubramanian          if(m_pOutput_pmem[i].buffer == MAP_FAILED)
29387783f07680c4e868295efbd0cf55a1622a106522Deva Ramasubramanian          {
29397783f07680c4e868295efbd0cf55a1622a106522Deva Ramasubramanian              DEBUG_PRINT_ERROR("\nERROR: MMAP_FAILED in o/p alloc buffer");
29407783f07680c4e868295efbd0cf55a1622a106522Deva Ramasubramanian              close (m_pOutput_pmem[i].fd);
2941826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#ifdef USE_ION
29427783f07680c4e868295efbd0cf55a1622a106522Deva Ramasubramanian              free_ion_memory(&m_pOutput_ion[i]);
2943826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#endif
29447783f07680c4e868295efbd0cf55a1622a106522Deva Ramasubramanian              return OMX_ErrorInsufficientResources;
29457783f07680c4e868295efbd0cf55a1622a106522Deva Ramasubramanian          }
294647e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
294747e37c4428509524ee576920a98381f3e4872493Nick Pelly
294847e37c4428509524ee576920a98381f3e4872493Nick Pelly      *bufferHdr = (m_out_mem_ptr + i );
29497783f07680c4e868295efbd0cf55a1622a106522Deva Ramasubramanian      if(!secure_session)
29507783f07680c4e868295efbd0cf55a1622a106522Deva Ramasubramanian        (*bufferHdr)->pBuffer = (OMX_U8 *)m_pOutput_pmem[i].buffer;
29517783f07680c4e868295efbd0cf55a1622a106522Deva Ramasubramanian      else {
29527783f07680c4e868295efbd0cf55a1622a106522Deva Ramasubramanian        m_pOutput_pmem[i].buffer = (OMX_U8 *)(i + 12345);
29537783f07680c4e868295efbd0cf55a1622a106522Deva Ramasubramanian        (*bufferHdr)->pBuffer = (OMX_U8 *)(i + 12345);
29547783f07680c4e868295efbd0cf55a1622a106522Deva Ramasubramanian      }
2955826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      (*bufferHdr)->pAppPrivate = appData;
295647e37c4428509524ee576920a98381f3e4872493Nick Pelly
295747e37c4428509524ee576920a98381f3e4872493Nick Pelly      BITMASK_SET(&m_out_bm_count,i);
295847e37c4428509524ee576920a98381f3e4872493Nick Pelly
2959826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      if(dev_use_buf(&m_pOutput_pmem[i],PORT_INDEX_OUT,i) != true)
296047e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
296147e37c4428509524ee576920a98381f3e4872493Nick Pelly        DEBUG_PRINT_ERROR("\nERROR: dev_use_buf FAILED for o/p buf");
296247e37c4428509524ee576920a98381f3e4872493Nick Pelly        return OMX_ErrorInsufficientResources;
296347e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
296447e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
296547e37c4428509524ee576920a98381f3e4872493Nick Pelly    else
296647e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
296747e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_ERROR("\nERROR: All o/p buffers are allocated, invalid allocate buf call"
296847e37c4428509524ee576920a98381f3e4872493Nick Pelly                        "for index [%d]\n", i);
296947e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
297047e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
297147e37c4428509524ee576920a98381f3e4872493Nick Pelly
297247e37c4428509524ee576920a98381f3e4872493Nick Pelly  return eRet;
297347e37c4428509524ee576920a98381f3e4872493Nick Pelly}
297447e37c4428509524ee576920a98381f3e4872493Nick Pelly
297547e37c4428509524ee576920a98381f3e4872493Nick Pelly
297647e37c4428509524ee576920a98381f3e4872493Nick Pelly// AllocateBuffer  -- API Call
297747e37c4428509524ee576920a98381f3e4872493Nick Pelly/* ======================================================================
297847e37c4428509524ee576920a98381f3e4872493Nick PellyFUNCTION
297947e37c4428509524ee576920a98381f3e4872493Nick Pelly  omx_video::AllocateBuffer
298047e37c4428509524ee576920a98381f3e4872493Nick Pelly
298147e37c4428509524ee576920a98381f3e4872493Nick PellyDESCRIPTION
298247e37c4428509524ee576920a98381f3e4872493Nick Pelly  Returns zero if all the buffers released..
298347e37c4428509524ee576920a98381f3e4872493Nick Pelly
298447e37c4428509524ee576920a98381f3e4872493Nick PellyPARAMETERS
298547e37c4428509524ee576920a98381f3e4872493Nick Pelly  None.
298647e37c4428509524ee576920a98381f3e4872493Nick Pelly
298747e37c4428509524ee576920a98381f3e4872493Nick PellyRETURN VALUE
298847e37c4428509524ee576920a98381f3e4872493Nick Pelly  true/false
298947e37c4428509524ee576920a98381f3e4872493Nick Pelly
299047e37c4428509524ee576920a98381f3e4872493Nick Pelly========================================================================== */
299147e37c4428509524ee576920a98381f3e4872493Nick PellyOMX_ERRORTYPE  omx_video::allocate_buffer(OMX_IN OMX_HANDLETYPE                hComp,
299247e37c4428509524ee576920a98381f3e4872493Nick Pelly                                          OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr,
299347e37c4428509524ee576920a98381f3e4872493Nick Pelly                                          OMX_IN OMX_U32                        port,
299447e37c4428509524ee576920a98381f3e4872493Nick Pelly                                          OMX_IN OMX_PTR                     appData,
299547e37c4428509524ee576920a98381f3e4872493Nick Pelly                                          OMX_IN OMX_U32                       bytes)
299647e37c4428509524ee576920a98381f3e4872493Nick Pelly{
299747e37c4428509524ee576920a98381f3e4872493Nick Pelly
299847e37c4428509524ee576920a98381f3e4872493Nick Pelly  OMX_ERRORTYPE eRet = OMX_ErrorNone; // OMX return type
299947e37c4428509524ee576920a98381f3e4872493Nick Pelly
3000826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  DEBUG_PRINT_LOW("\n Allocate buffer of size = %d on port %d \n", bytes, (int)port);
300147e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(m_state == OMX_StateInvalid)
300247e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
300347e37c4428509524ee576920a98381f3e4872493Nick Pelly    DEBUG_PRINT_ERROR("ERROR: Allocate Buf in Invalid State\n");
300447e37c4428509524ee576920a98381f3e4872493Nick Pelly    return OMX_ErrorInvalidState;
300547e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
300647e37c4428509524ee576920a98381f3e4872493Nick Pelly
300747e37c4428509524ee576920a98381f3e4872493Nick Pelly  // What if the client calls again.
300847e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(port == PORT_INDEX_IN)
300947e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
3010826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#ifdef _ANDROID_ICS_
3011826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    if(meta_mode_enable)
30127eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      eRet = allocate_input_meta_buffer(hComp,bufferHdr,appData,bytes);
3013826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    else
3014826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#endif
301547e37c4428509524ee576920a98381f3e4872493Nick Pelly    eRet = allocate_input_buffer(hComp,bufferHdr,port,appData,bytes);
301647e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
301747e37c4428509524ee576920a98381f3e4872493Nick Pelly  else if(port == PORT_INDEX_OUT)
301847e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
301947e37c4428509524ee576920a98381f3e4872493Nick Pelly    eRet = allocate_output_buffer(hComp,bufferHdr,port,appData,bytes);
302047e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
302147e37c4428509524ee576920a98381f3e4872493Nick Pelly  else
302247e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
302347e37c4428509524ee576920a98381f3e4872493Nick Pelly    DEBUG_PRINT_ERROR("ERROR: Invalid Port Index received %d\n",(int)port);
302447e37c4428509524ee576920a98381f3e4872493Nick Pelly    eRet = OMX_ErrorBadPortIndex;
302547e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
302647e37c4428509524ee576920a98381f3e4872493Nick Pelly  DEBUG_PRINT_LOW("Checking for Output Allocate buffer Done");
302747e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(eRet == OMX_ErrorNone)
302847e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
302947e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(allocate_done())
303047e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
303147e37c4428509524ee576920a98381f3e4872493Nick Pelly      if(BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING))
303247e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
303347e37c4428509524ee576920a98381f3e4872493Nick Pelly        // Send the callback now
303447e37c4428509524ee576920a98381f3e4872493Nick Pelly        BITMASK_CLEAR((&m_flags),OMX_COMPONENT_IDLE_PENDING);
303547e37c4428509524ee576920a98381f3e4872493Nick Pelly        post_event(OMX_CommandStateSet,OMX_StateIdle,
303647e37c4428509524ee576920a98381f3e4872493Nick Pelly                   OMX_COMPONENT_GENERATE_EVENT);
303747e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
303847e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
303947e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(port == PORT_INDEX_IN && m_sInPortDef.bPopulated)
304047e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
304147e37c4428509524ee576920a98381f3e4872493Nick Pelly      if(BITMASK_PRESENT(&m_flags,OMX_COMPONENT_INPUT_ENABLE_PENDING))
304247e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
304347e37c4428509524ee576920a98381f3e4872493Nick Pelly        BITMASK_CLEAR((&m_flags),OMX_COMPONENT_INPUT_ENABLE_PENDING);
304447e37c4428509524ee576920a98381f3e4872493Nick Pelly        post_event(OMX_CommandPortEnable,
304547e37c4428509524ee576920a98381f3e4872493Nick Pelly                   PORT_INDEX_IN,
304647e37c4428509524ee576920a98381f3e4872493Nick Pelly                   OMX_COMPONENT_GENERATE_EVENT);
304747e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
304847e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
304947e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(port == PORT_INDEX_OUT && m_sOutPortDef.bPopulated)
305047e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
305147e37c4428509524ee576920a98381f3e4872493Nick Pelly      if(BITMASK_PRESENT(&m_flags,OMX_COMPONENT_OUTPUT_ENABLE_PENDING))
305247e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
305347e37c4428509524ee576920a98381f3e4872493Nick Pelly        BITMASK_CLEAR((&m_flags),OMX_COMPONENT_OUTPUT_ENABLE_PENDING);
305447e37c4428509524ee576920a98381f3e4872493Nick Pelly        post_event(OMX_CommandPortEnable,
305547e37c4428509524ee576920a98381f3e4872493Nick Pelly                   PORT_INDEX_OUT,
305647e37c4428509524ee576920a98381f3e4872493Nick Pelly                   OMX_COMPONENT_GENERATE_EVENT);
305747e37c4428509524ee576920a98381f3e4872493Nick Pelly        m_event_port_settings_sent = false;
305847e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
305947e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
306047e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
306147e37c4428509524ee576920a98381f3e4872493Nick Pelly  DEBUG_PRINT_LOW("Allocate Buffer exit with ret Code %d\n",eRet);
306247e37c4428509524ee576920a98381f3e4872493Nick Pelly  return eRet;
306347e37c4428509524ee576920a98381f3e4872493Nick Pelly}
306447e37c4428509524ee576920a98381f3e4872493Nick Pelly
306547e37c4428509524ee576920a98381f3e4872493Nick Pelly
306647e37c4428509524ee576920a98381f3e4872493Nick Pelly// Free Buffer - API call
306747e37c4428509524ee576920a98381f3e4872493Nick Pelly/* ======================================================================
306847e37c4428509524ee576920a98381f3e4872493Nick PellyFUNCTION
306947e37c4428509524ee576920a98381f3e4872493Nick Pelly  omx_video::FreeBuffer
307047e37c4428509524ee576920a98381f3e4872493Nick Pelly
307147e37c4428509524ee576920a98381f3e4872493Nick PellyDESCRIPTION
307247e37c4428509524ee576920a98381f3e4872493Nick Pelly
307347e37c4428509524ee576920a98381f3e4872493Nick PellyPARAMETERS
307447e37c4428509524ee576920a98381f3e4872493Nick Pelly  None.
307547e37c4428509524ee576920a98381f3e4872493Nick Pelly
307647e37c4428509524ee576920a98381f3e4872493Nick PellyRETURN VALUE
307747e37c4428509524ee576920a98381f3e4872493Nick Pelly  true/false
307847e37c4428509524ee576920a98381f3e4872493Nick Pelly
307947e37c4428509524ee576920a98381f3e4872493Nick Pelly========================================================================== */
308047e37c4428509524ee576920a98381f3e4872493Nick PellyOMX_ERRORTYPE  omx_video::free_buffer(OMX_IN OMX_HANDLETYPE         hComp,
308147e37c4428509524ee576920a98381f3e4872493Nick Pelly                                      OMX_IN OMX_U32                 port,
308247e37c4428509524ee576920a98381f3e4872493Nick Pelly                                      OMX_IN OMX_BUFFERHEADERTYPE* buffer)
308347e37c4428509524ee576920a98381f3e4872493Nick Pelly{
308447e37c4428509524ee576920a98381f3e4872493Nick Pelly  OMX_ERRORTYPE eRet = OMX_ErrorNone;
308547e37c4428509524ee576920a98381f3e4872493Nick Pelly  unsigned int nPortIndex;
308647e37c4428509524ee576920a98381f3e4872493Nick Pelly
308747e37c4428509524ee576920a98381f3e4872493Nick Pelly  DEBUG_PRINT_LOW("In for decoder free_buffer \n");
308847e37c4428509524ee576920a98381f3e4872493Nick Pelly
308947e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(m_state == OMX_StateIdle &&
309047e37c4428509524ee576920a98381f3e4872493Nick Pelly     (BITMASK_PRESENT(&m_flags ,OMX_COMPONENT_LOADING_PENDING)))
309147e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
309247e37c4428509524ee576920a98381f3e4872493Nick Pelly    DEBUG_PRINT_LOW(" free buffer while Component in Loading pending\n");
309347e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
309447e37c4428509524ee576920a98381f3e4872493Nick Pelly  else if((m_sInPortDef.bEnabled == OMX_FALSE && port == PORT_INDEX_IN)||
309547e37c4428509524ee576920a98381f3e4872493Nick Pelly          (m_sOutPortDef.bEnabled == OMX_FALSE && port == PORT_INDEX_OUT))
309647e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
309747e37c4428509524ee576920a98381f3e4872493Nick Pelly    DEBUG_PRINT_LOW("Free Buffer while port %d disabled\n", port);
309847e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
309947e37c4428509524ee576920a98381f3e4872493Nick Pelly  else if(m_state == OMX_StateExecuting || m_state == OMX_StatePause)
310047e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
310147e37c4428509524ee576920a98381f3e4872493Nick Pelly    DEBUG_PRINT_ERROR("ERROR: Invalid state to free buffer,ports need to be disabled\n");
310247e37c4428509524ee576920a98381f3e4872493Nick Pelly    post_event(OMX_EventError,
310347e37c4428509524ee576920a98381f3e4872493Nick Pelly               OMX_ErrorPortUnpopulated,
310447e37c4428509524ee576920a98381f3e4872493Nick Pelly               OMX_COMPONENT_GENERATE_EVENT);
310547e37c4428509524ee576920a98381f3e4872493Nick Pelly
310647e37c4428509524ee576920a98381f3e4872493Nick Pelly    return eRet;
310747e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
310847e37c4428509524ee576920a98381f3e4872493Nick Pelly  else
310947e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
311047e37c4428509524ee576920a98381f3e4872493Nick Pelly    DEBUG_PRINT_ERROR("ERROR: Invalid state to free buffer,port lost Buffers\n");
311147e37c4428509524ee576920a98381f3e4872493Nick Pelly    post_event(OMX_EventError,
311247e37c4428509524ee576920a98381f3e4872493Nick Pelly               OMX_ErrorPortUnpopulated,
311347e37c4428509524ee576920a98381f3e4872493Nick Pelly               OMX_COMPONENT_GENERATE_EVENT);
311447e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
311547e37c4428509524ee576920a98381f3e4872493Nick Pelly
311647e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(port == PORT_INDEX_IN)
311747e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
311847e37c4428509524ee576920a98381f3e4872493Nick Pelly    // check if the buffer is valid
31197eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    nPortIndex = buffer - ((!mUseProxyColorFormat)?m_inp_mem_ptr:meta_buffer_hdr);
312047e37c4428509524ee576920a98381f3e4872493Nick Pelly
312147e37c4428509524ee576920a98381f3e4872493Nick Pelly    DEBUG_PRINT_LOW("free_buffer on i/p port - Port idx %d, actual cnt %d \n",
312247e37c4428509524ee576920a98381f3e4872493Nick Pelly                    nPortIndex, m_sInPortDef.nBufferCountActual);
312347e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(nPortIndex < m_sInPortDef.nBufferCountActual)
312447e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
312547e37c4428509524ee576920a98381f3e4872493Nick Pelly      // Clear the bit associated with it.
312647e37c4428509524ee576920a98381f3e4872493Nick Pelly      BITMASK_CLEAR(&m_inp_bm_count,nPortIndex);
312747e37c4428509524ee576920a98381f3e4872493Nick Pelly      free_input_buffer (buffer);
312847e37c4428509524ee576920a98381f3e4872493Nick Pelly      m_sInPortDef.bPopulated = OMX_FALSE;
312947e37c4428509524ee576920a98381f3e4872493Nick Pelly
313047e37c4428509524ee576920a98381f3e4872493Nick Pelly      /*Free the Buffer Header*/
3131826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      if(release_input_done()
3132826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#ifdef _ANDROID_ICS_
3133826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev         && !meta_mode_enable
3134826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#endif
3135826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev         )
313647e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
313747e37c4428509524ee576920a98381f3e4872493Nick Pelly        input_use_buffer = false;
313847e37c4428509524ee576920a98381f3e4872493Nick Pelly        if(m_inp_mem_ptr)
313947e37c4428509524ee576920a98381f3e4872493Nick Pelly        {
314047e37c4428509524ee576920a98381f3e4872493Nick Pelly          DEBUG_PRINT_LOW("Freeing m_inp_mem_ptr\n");
314147e37c4428509524ee576920a98381f3e4872493Nick Pelly          free (m_inp_mem_ptr);
314247e37c4428509524ee576920a98381f3e4872493Nick Pelly          m_inp_mem_ptr = NULL;
314347e37c4428509524ee576920a98381f3e4872493Nick Pelly        }
314447e37c4428509524ee576920a98381f3e4872493Nick Pelly        if(m_pInput_pmem)
314547e37c4428509524ee576920a98381f3e4872493Nick Pelly        {
314647e37c4428509524ee576920a98381f3e4872493Nick Pelly          DEBUG_PRINT_LOW("Freeing m_pInput_pmem\n");
314747e37c4428509524ee576920a98381f3e4872493Nick Pelly          free(m_pInput_pmem);
314847e37c4428509524ee576920a98381f3e4872493Nick Pelly          m_pInput_pmem = NULL;
314947e37c4428509524ee576920a98381f3e4872493Nick Pelly        }
3150826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#ifdef USE_ION
3151826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        if(m_pInput_ion)
3152826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        {
3153826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev          DEBUG_PRINT_LOW("Freeing m_pInput_ion\n");
3154826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev          free(m_pInput_ion);
3155826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev          m_pInput_ion = NULL;
3156826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        }
3157826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#endif
315847e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
315947e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
316047e37c4428509524ee576920a98381f3e4872493Nick Pelly    else
316147e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
316247e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_ERROR("ERROR: free_buffer ,Port Index Invalid\n");
316347e37c4428509524ee576920a98381f3e4872493Nick Pelly      eRet = OMX_ErrorBadPortIndex;
316447e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
316547e37c4428509524ee576920a98381f3e4872493Nick Pelly
316647e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(BITMASK_PRESENT((&m_flags),OMX_COMPONENT_INPUT_DISABLE_PENDING)
316747e37c4428509524ee576920a98381f3e4872493Nick Pelly       && release_input_done())
316847e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
316947e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_LOW("MOVING TO DISABLED STATE \n");
317047e37c4428509524ee576920a98381f3e4872493Nick Pelly      BITMASK_CLEAR((&m_flags),OMX_COMPONENT_INPUT_DISABLE_PENDING);
317147e37c4428509524ee576920a98381f3e4872493Nick Pelly      post_event(OMX_CommandPortDisable,
317247e37c4428509524ee576920a98381f3e4872493Nick Pelly                 PORT_INDEX_IN,
317347e37c4428509524ee576920a98381f3e4872493Nick Pelly                 OMX_COMPONENT_GENERATE_EVENT);
317447e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
317547e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
317647e37c4428509524ee576920a98381f3e4872493Nick Pelly  else if(port == PORT_INDEX_OUT)
317747e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
317847e37c4428509524ee576920a98381f3e4872493Nick Pelly    // check if the buffer is valid
317947e37c4428509524ee576920a98381f3e4872493Nick Pelly    nPortIndex = buffer - (OMX_BUFFERHEADERTYPE*)m_out_mem_ptr;
318047e37c4428509524ee576920a98381f3e4872493Nick Pelly
318147e37c4428509524ee576920a98381f3e4872493Nick Pelly    DEBUG_PRINT_LOW("free_buffer on o/p port - Port idx %d, actual cnt %d \n",
318247e37c4428509524ee576920a98381f3e4872493Nick Pelly                    nPortIndex, m_sOutPortDef.nBufferCountActual);
318347e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(nPortIndex < m_sOutPortDef.nBufferCountActual)
318447e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
318547e37c4428509524ee576920a98381f3e4872493Nick Pelly      // Clear the bit associated with it.
318647e37c4428509524ee576920a98381f3e4872493Nick Pelly      BITMASK_CLEAR(&m_out_bm_count,nPortIndex);
318747e37c4428509524ee576920a98381f3e4872493Nick Pelly      m_sOutPortDef.bPopulated = OMX_FALSE;
318847e37c4428509524ee576920a98381f3e4872493Nick Pelly      free_output_buffer (buffer);
318947e37c4428509524ee576920a98381f3e4872493Nick Pelly
319047e37c4428509524ee576920a98381f3e4872493Nick Pelly      if(release_output_done())
319147e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
319247e37c4428509524ee576920a98381f3e4872493Nick Pelly        output_use_buffer = false;
319347e37c4428509524ee576920a98381f3e4872493Nick Pelly        if(m_out_mem_ptr)
319447e37c4428509524ee576920a98381f3e4872493Nick Pelly        {
319547e37c4428509524ee576920a98381f3e4872493Nick Pelly          DEBUG_PRINT_LOW("Freeing m_out_mem_ptr\n");
319647e37c4428509524ee576920a98381f3e4872493Nick Pelly          free (m_out_mem_ptr);
319747e37c4428509524ee576920a98381f3e4872493Nick Pelly          m_out_mem_ptr = NULL;
319847e37c4428509524ee576920a98381f3e4872493Nick Pelly        }
319947e37c4428509524ee576920a98381f3e4872493Nick Pelly        if(m_pOutput_pmem)
320047e37c4428509524ee576920a98381f3e4872493Nick Pelly        {
320147e37c4428509524ee576920a98381f3e4872493Nick Pelly          DEBUG_PRINT_LOW("Freeing m_pOutput_pmem\n");
320247e37c4428509524ee576920a98381f3e4872493Nick Pelly          free(m_pOutput_pmem);
320347e37c4428509524ee576920a98381f3e4872493Nick Pelly          m_pOutput_pmem = NULL;
320447e37c4428509524ee576920a98381f3e4872493Nick Pelly        }
3205826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#ifdef USE_ION
3206826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        if(m_pOutput_ion)
3207826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        {
3208826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev          DEBUG_PRINT_LOW("Freeing m_pOutput_ion\n");
3209826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev          free(m_pOutput_ion);
3210826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev          m_pOutput_ion = NULL;
3211826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        }
3212826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#endif
321347e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
321447e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
321547e37c4428509524ee576920a98381f3e4872493Nick Pelly    else
321647e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
321747e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_ERROR("ERROR: free_buffer , Port Index Invalid\n");
321847e37c4428509524ee576920a98381f3e4872493Nick Pelly      eRet = OMX_ErrorBadPortIndex;
321947e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
322047e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(BITMASK_PRESENT((&m_flags),OMX_COMPONENT_OUTPUT_DISABLE_PENDING)
322147e37c4428509524ee576920a98381f3e4872493Nick Pelly       && release_output_done() )
322247e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
322347e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_LOW("FreeBuffer : If any Disable event pending,post it\n");
322447e37c4428509524ee576920a98381f3e4872493Nick Pelly
322547e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_LOW("MOVING TO DISABLED STATE \n");
322647e37c4428509524ee576920a98381f3e4872493Nick Pelly      BITMASK_CLEAR((&m_flags),OMX_COMPONENT_OUTPUT_DISABLE_PENDING);
322747e37c4428509524ee576920a98381f3e4872493Nick Pelly      post_event(OMX_CommandPortDisable,
322847e37c4428509524ee576920a98381f3e4872493Nick Pelly                 PORT_INDEX_OUT,
322947e37c4428509524ee576920a98381f3e4872493Nick Pelly                 OMX_COMPONENT_GENERATE_EVENT);
323047e37c4428509524ee576920a98381f3e4872493Nick Pelly
323147e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
323247e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
323347e37c4428509524ee576920a98381f3e4872493Nick Pelly  else
323447e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
323547e37c4428509524ee576920a98381f3e4872493Nick Pelly    eRet = OMX_ErrorBadPortIndex;
323647e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
323747e37c4428509524ee576920a98381f3e4872493Nick Pelly  if((eRet == OMX_ErrorNone) &&
323847e37c4428509524ee576920a98381f3e4872493Nick Pelly     (BITMASK_PRESENT(&m_flags ,OMX_COMPONENT_LOADING_PENDING)))
323947e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
324047e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(release_done())
324147e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
324247e37c4428509524ee576920a98381f3e4872493Nick Pelly      if(dev_stop() != 0)
324347e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
324447e37c4428509524ee576920a98381f3e4872493Nick Pelly        DEBUG_PRINT_ERROR("ERROR: dev_stop() FAILED\n");
324547e37c4428509524ee576920a98381f3e4872493Nick Pelly        eRet = OMX_ErrorHardware;
324647e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
324747e37c4428509524ee576920a98381f3e4872493Nick Pelly      // Send the callback now
324847e37c4428509524ee576920a98381f3e4872493Nick Pelly      BITMASK_CLEAR((&m_flags),OMX_COMPONENT_LOADING_PENDING);
324947e37c4428509524ee576920a98381f3e4872493Nick Pelly      post_event(OMX_CommandStateSet, OMX_StateLoaded,
325047e37c4428509524ee576920a98381f3e4872493Nick Pelly                 OMX_COMPONENT_GENERATE_EVENT);
325147e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
325247e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
325347e37c4428509524ee576920a98381f3e4872493Nick Pelly
325447e37c4428509524ee576920a98381f3e4872493Nick Pelly  return eRet;
325547e37c4428509524ee576920a98381f3e4872493Nick Pelly}
325647e37c4428509524ee576920a98381f3e4872493Nick Pelly
325747e37c4428509524ee576920a98381f3e4872493Nick Pelly
325847e37c4428509524ee576920a98381f3e4872493Nick Pelly/* ======================================================================
325947e37c4428509524ee576920a98381f3e4872493Nick PellyFUNCTION
326047e37c4428509524ee576920a98381f3e4872493Nick Pelly  omx_video::EmptyThisBuffer
326147e37c4428509524ee576920a98381f3e4872493Nick Pelly
326247e37c4428509524ee576920a98381f3e4872493Nick PellyDESCRIPTION
326347e37c4428509524ee576920a98381f3e4872493Nick Pelly  This routine is used to push the encoded video frames to
326447e37c4428509524ee576920a98381f3e4872493Nick Pelly  the video decoder.
326547e37c4428509524ee576920a98381f3e4872493Nick Pelly
326647e37c4428509524ee576920a98381f3e4872493Nick PellyPARAMETERS
326747e37c4428509524ee576920a98381f3e4872493Nick Pelly  None.
326847e37c4428509524ee576920a98381f3e4872493Nick Pelly
326947e37c4428509524ee576920a98381f3e4872493Nick PellyRETURN VALUE
327047e37c4428509524ee576920a98381f3e4872493Nick Pelly  OMX Error None if everything went successful.
327147e37c4428509524ee576920a98381f3e4872493Nick Pelly
327247e37c4428509524ee576920a98381f3e4872493Nick Pelly========================================================================== */
327347e37c4428509524ee576920a98381f3e4872493Nick PellyOMX_ERRORTYPE  omx_video::empty_this_buffer(OMX_IN OMX_HANDLETYPE         hComp,
327447e37c4428509524ee576920a98381f3e4872493Nick Pelly                                            OMX_IN OMX_BUFFERHEADERTYPE* buffer)
327547e37c4428509524ee576920a98381f3e4872493Nick Pelly{
327647e37c4428509524ee576920a98381f3e4872493Nick Pelly  OMX_ERRORTYPE ret1 = OMX_ErrorNone;
327747e37c4428509524ee576920a98381f3e4872493Nick Pelly  unsigned int nBufferIndex ;
327847e37c4428509524ee576920a98381f3e4872493Nick Pelly
327947e37c4428509524ee576920a98381f3e4872493Nick Pelly  DEBUG_PRINT_LOW("\n ETB: buffer = %p, buffer->pBuffer[%p]\n", buffer, buffer->pBuffer);
328047e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(m_state == OMX_StateInvalid)
328147e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
328247e37c4428509524ee576920a98381f3e4872493Nick Pelly    DEBUG_PRINT_ERROR("ERROR: Empty this buffer in Invalid State\n");
328347e37c4428509524ee576920a98381f3e4872493Nick Pelly    return OMX_ErrorInvalidState;
328447e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
328547e37c4428509524ee576920a98381f3e4872493Nick Pelly
328647e37c4428509524ee576920a98381f3e4872493Nick Pelly  if (buffer == NULL || (buffer->nSize != sizeof(OMX_BUFFERHEADERTYPE)))
328747e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
328847e37c4428509524ee576920a98381f3e4872493Nick Pelly    DEBUG_PRINT_ERROR("\nERROR: omx_video::etb--> buffer is null or buffer size is invalid");
328947e37c4428509524ee576920a98381f3e4872493Nick Pelly    return OMX_ErrorBadParameter;
329047e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
329147e37c4428509524ee576920a98381f3e4872493Nick Pelly
329247e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(buffer->nVersion.nVersion != OMX_SPEC_VERSION)
329347e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
329447e37c4428509524ee576920a98381f3e4872493Nick Pelly    DEBUG_PRINT_ERROR("\nERROR: omx_video::etb--> OMX Version Invalid");
329547e37c4428509524ee576920a98381f3e4872493Nick Pelly    return OMX_ErrorVersionMismatch;
329647e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
329747e37c4428509524ee576920a98381f3e4872493Nick Pelly
329847e37c4428509524ee576920a98381f3e4872493Nick Pelly  if (buffer->nInputPortIndex != (OMX_U32)PORT_INDEX_IN)
329947e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
330047e37c4428509524ee576920a98381f3e4872493Nick Pelly    DEBUG_PRINT_ERROR("\nERROR: Bad port index to call empty_this_buffer");
330147e37c4428509524ee576920a98381f3e4872493Nick Pelly    return OMX_ErrorBadPortIndex;
330247e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
330347e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(!m_sInPortDef.bEnabled)
330447e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
330547e37c4428509524ee576920a98381f3e4872493Nick Pelly    DEBUG_PRINT_ERROR("\nERROR: Cannot call empty_this_buffer while I/P port is disabled");
330647e37c4428509524ee576920a98381f3e4872493Nick Pelly    return OMX_ErrorIncorrectStateOperation;
330747e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
330847e37c4428509524ee576920a98381f3e4872493Nick Pelly
33097eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  nBufferIndex = buffer - ((!mUseProxyColorFormat)?m_inp_mem_ptr:meta_buffer_hdr);
331047e37c4428509524ee576920a98381f3e4872493Nick Pelly
331147e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(nBufferIndex > m_sInPortDef.nBufferCountActual )
331247e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
331347e37c4428509524ee576920a98381f3e4872493Nick Pelly    DEBUG_PRINT_ERROR("ERROR: ETB: Invalid buffer index[%d]\n", nBufferIndex);
331447e37c4428509524ee576920a98381f3e4872493Nick Pelly    return OMX_ErrorBadParameter;
331547e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
331647e37c4428509524ee576920a98381f3e4872493Nick Pelly
331747e37c4428509524ee576920a98381f3e4872493Nick Pelly  m_etb_count++;
331847e37c4428509524ee576920a98381f3e4872493Nick Pelly  DEBUG_PRINT_LOW("\n DBG: i/p nTimestamp = %u", (unsigned)buffer->nTimeStamp);
33197eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  post_event ((unsigned)hComp,(unsigned)buffer,m_input_msg_id);
332047e37c4428509524ee576920a98381f3e4872493Nick Pelly  return OMX_ErrorNone;
332147e37c4428509524ee576920a98381f3e4872493Nick Pelly}
332247e37c4428509524ee576920a98381f3e4872493Nick Pelly/* ======================================================================
332347e37c4428509524ee576920a98381f3e4872493Nick PellyFUNCTION
332447e37c4428509524ee576920a98381f3e4872493Nick Pelly  omx_video::empty_this_buffer_proxy
332547e37c4428509524ee576920a98381f3e4872493Nick Pelly
332647e37c4428509524ee576920a98381f3e4872493Nick PellyDESCRIPTION
332747e37c4428509524ee576920a98381f3e4872493Nick Pelly  This routine is used to push the encoded video frames to
332847e37c4428509524ee576920a98381f3e4872493Nick Pelly  the video decoder.
332947e37c4428509524ee576920a98381f3e4872493Nick Pelly
333047e37c4428509524ee576920a98381f3e4872493Nick PellyPARAMETERS
333147e37c4428509524ee576920a98381f3e4872493Nick Pelly  None.
333247e37c4428509524ee576920a98381f3e4872493Nick Pelly
333347e37c4428509524ee576920a98381f3e4872493Nick PellyRETURN VALUE
333447e37c4428509524ee576920a98381f3e4872493Nick Pelly  OMX Error None if everything went successful.
333547e37c4428509524ee576920a98381f3e4872493Nick Pelly
333647e37c4428509524ee576920a98381f3e4872493Nick Pelly========================================================================== */
333747e37c4428509524ee576920a98381f3e4872493Nick PellyOMX_ERRORTYPE  omx_video::empty_this_buffer_proxy(OMX_IN OMX_HANDLETYPE         hComp,
333847e37c4428509524ee576920a98381f3e4872493Nick Pelly                                                  OMX_IN OMX_BUFFERHEADERTYPE* buffer)
333947e37c4428509524ee576920a98381f3e4872493Nick Pelly{
334047e37c4428509524ee576920a98381f3e4872493Nick Pelly  OMX_U8 *pmem_data_buf = NULL;
334147e37c4428509524ee576920a98381f3e4872493Nick Pelly  int push_cnt = 0;
33427eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  unsigned nBufIndex = 0,nBufIndex_meta = 0;
334347e37c4428509524ee576920a98381f3e4872493Nick Pelly  OMX_ERRORTYPE ret = OMX_ErrorNone;
334447e37c4428509524ee576920a98381f3e4872493Nick Pelly
33457eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  DEBUG_PRINT_LOW("\n ETBProxy: buffer[%p]\n", buffer);
334647e37c4428509524ee576920a98381f3e4872493Nick Pelly
334747e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(buffer == NULL)
334847e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
334947e37c4428509524ee576920a98381f3e4872493Nick Pelly    DEBUG_PRINT_ERROR("\nERROR: ETBProxy: Invalid buffer[%p]\n", buffer);
335047e37c4428509524ee576920a98381f3e4872493Nick Pelly    return OMX_ErrorBadParameter;
335147e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
335247e37c4428509524ee576920a98381f3e4872493Nick Pelly
335347e37c4428509524ee576920a98381f3e4872493Nick Pelly  nBufIndex = buffer - ((OMX_BUFFERHEADERTYPE *)m_inp_mem_ptr);
33547eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  nBufIndex_meta = buffer - meta_buffer_hdr;
33557eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  if(nBufIndex >= m_sInPortDef.nBufferCountActual &&
33567eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George     nBufIndex_meta >= m_sInPortDef.nBufferCountActual)
335747e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
335847e37c4428509524ee576920a98381f3e4872493Nick Pelly    DEBUG_PRINT_ERROR("\nERROR: ETBProxy: Invalid bufindex = %u\n", nBufIndex);
335947e37c4428509524ee576920a98381f3e4872493Nick Pelly    return OMX_ErrorBadParameter;
336047e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
336147e37c4428509524ee576920a98381f3e4872493Nick Pelly
336247e37c4428509524ee576920a98381f3e4872493Nick Pelly  pending_input_buffers++;
336347e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(input_flush_progress == true)
336447e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
336547e37c4428509524ee576920a98381f3e4872493Nick Pelly    post_event ((unsigned int)buffer,0,
336647e37c4428509524ee576920a98381f3e4872493Nick Pelly                OMX_COMPONENT_GENERATE_EBD);
336747e37c4428509524ee576920a98381f3e4872493Nick Pelly    DEBUG_PRINT_ERROR("\nERROR: ETBProxy: Input flush in progress");
336847e37c4428509524ee576920a98381f3e4872493Nick Pelly    return OMX_ErrorNone;
336947e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
3370826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#ifdef _ANDROID_ICS_
33717eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  if(meta_mode_enable && !mUseProxyColorFormat)
3372826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  {
3373826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    encoder_media_buffer_type *media_buffer;
3374826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    bool met_error = false;
3375826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    media_buffer = (encoder_media_buffer_type *)meta_buffer_hdr[nBufIndex].pBuffer;
3376826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    if(media_buffer)
3377826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    {
3378826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      if (media_buffer->buffer_type != kMetadataBufferTypeCameraSource &&
3379826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev          media_buffer->buffer_type != kMetadataBufferTypeGrallocSource) {
3380826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev          met_error = true;
3381826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      } else {
3382826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        if(media_buffer->buffer_type == kMetadataBufferTypeCameraSource)
3383826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        {
3384826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev          if(media_buffer->meta_handle == NULL) {
3385826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev            met_error = true;
3386826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev          }
3387826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev          else if((media_buffer->meta_handle->numFds != 1 &&
3388826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev                   media_buffer->meta_handle->numInts != 2))
3389826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev          {
3390826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev            met_error = true;
3391826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev          }
3392826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        }
3393826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      }
3394826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    } else {
3395826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      met_error = true;
3396826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    }
3397826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    if(met_error)
3398826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    {
3399826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      DEBUG_PRINT_ERROR("\nERROR: Unkown source/metahandle in ETB call");
3400826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      post_event ((unsigned int)buffer,0,OMX_COMPONENT_GENERATE_EBD);
3401826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      return OMX_ErrorBadParameter;
3402826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    }
340347e37c4428509524ee576920a98381f3e4872493Nick Pelly
3404826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    struct pmem Input_pmem_info;
3405826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    if(media_buffer->buffer_type == kMetadataBufferTypeCameraSource)
3406826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    {
3407826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      Input_pmem_info.buffer = media_buffer;
3408826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      Input_pmem_info.fd = media_buffer->meta_handle->data[0];
3409826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      Input_pmem_info.offset = media_buffer->meta_handle->data[1];
3410826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      Input_pmem_info.size = media_buffer->meta_handle->data[2];
3411826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      DEBUG_PRINT_LOW("ETB fd = %d, offset = %d, size = %d",Input_pmem_info.fd,
3412826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev                        Input_pmem_info.offset,
3413826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev                        Input_pmem_info.size);
3414826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev
3415826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    } else {
3416826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      private_handle_t *handle = (private_handle_t *)media_buffer->meta_handle;
34177783f07680c4e868295efbd0cf55a1622a106522Deva Ramasubramanian      if(handle->format != HAL_PIXEL_FORMAT_NV12_ENCODEABLE) {
34187783f07680c4e868295efbd0cf55a1622a106522Deva Ramasubramanian        DEBUG_PRINT_ERROR("\n Incorrect pixel format");
34197783f07680c4e868295efbd0cf55a1622a106522Deva Ramasubramanian        post_event ((unsigned int)buffer,0,OMX_COMPONENT_GENERATE_EBD);
34207783f07680c4e868295efbd0cf55a1622a106522Deva Ramasubramanian        return OMX_ErrorBadParameter;
34217783f07680c4e868295efbd0cf55a1622a106522Deva Ramasubramanian      }
3422826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      Input_pmem_info.buffer = media_buffer;
3423826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      Input_pmem_info.fd = handle->fd;
3424826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      Input_pmem_info.offset = 0;
3425826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      Input_pmem_info.size = handle->size;
3426826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    }
3427826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    if(dev_use_buf(&Input_pmem_info,PORT_INDEX_IN,0) != true) {
3428826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      DEBUG_PRINT_ERROR("\nERROR: in dev_use_buf");
3429826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      post_event ((unsigned int)buffer,0,OMX_COMPONENT_GENERATE_EBD);
3430826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      return OMX_ErrorBadParameter;
3431826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    }
3432826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  }
3433826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  else if(input_use_buffer && !m_use_input_pmem)
3434826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#else
343547e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(input_use_buffer && !m_use_input_pmem)
3436826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#endif
343747e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
343847e37c4428509524ee576920a98381f3e4872493Nick Pelly    DEBUG_PRINT_LOW("\n Heap UseBuffer case, so memcpy the data");
343947e37c4428509524ee576920a98381f3e4872493Nick Pelly    pmem_data_buf = (OMX_U8 *)m_pInput_pmem[nBufIndex].buffer;
344047e37c4428509524ee576920a98381f3e4872493Nick Pelly
344147e37c4428509524ee576920a98381f3e4872493Nick Pelly    memcpy (pmem_data_buf, (buffer->pBuffer + buffer->nOffset),
344247e37c4428509524ee576920a98381f3e4872493Nick Pelly            buffer->nFilledLen);
344347e37c4428509524ee576920a98381f3e4872493Nick Pelly    DEBUG_PRINT_LOW("memcpy() done in ETBProxy for i/p Heap UseBuf");
3444525cc9b815b0cb86e4fc02be0bfa5f1e363804f6Praveen Chavan  } else if (m_sInPortDef.format.video.eColorFormat ==
3445525cc9b815b0cb86e4fc02be0bfa5f1e363804f6Praveen Chavan      OMX_COLOR_FormatYUV420SemiPlanar && !mUseProxyColorFormat) {
3446525cc9b815b0cb86e4fc02be0bfa5f1e363804f6Praveen Chavan      //For the case where YUV420SP buffers are qeueued to component
3447525cc9b815b0cb86e4fc02be0bfa5f1e363804f6Praveen Chavan      //by sources other than camera (Apps via MediaCodec), alignment
3448525cc9b815b0cb86e4fc02be0bfa5f1e363804f6Praveen Chavan      //of chroma-plane to 2K is necessary.
3449525cc9b815b0cb86e4fc02be0bfa5f1e363804f6Praveen Chavan      //For RGB buffers, color-conversion takes care of such alignment
3450525cc9b815b0cb86e4fc02be0bfa5f1e363804f6Praveen Chavan      OMX_U32 width = m_sInPortDef.format.video.nFrameWidth;
3451525cc9b815b0cb86e4fc02be0bfa5f1e363804f6Praveen Chavan      OMX_U32 height = m_sInPortDef.format.video.nFrameHeight;
3452525cc9b815b0cb86e4fc02be0bfa5f1e363804f6Praveen Chavan      OMX_U32 chromaOffset = width * height;
3453525cc9b815b0cb86e4fc02be0bfa5f1e363804f6Praveen Chavan      if (IS_NOT_ALIGNED(chromaOffset, SZ_2K)) {
3454525cc9b815b0cb86e4fc02be0bfa5f1e363804f6Praveen Chavan          OMX_U32 chromaSize = (width * height)/2;
3455525cc9b815b0cb86e4fc02be0bfa5f1e363804f6Praveen Chavan          chromaOffset = ALIGN(chromaOffset,SZ_2K);
3456525cc9b815b0cb86e4fc02be0bfa5f1e363804f6Praveen Chavan          if (buffer->nAllocLen >= chromaOffset + chromaSize) {
3457525cc9b815b0cb86e4fc02be0bfa5f1e363804f6Praveen Chavan              OMX_U8* buf = buffer->pBuffer;
3458525cc9b815b0cb86e4fc02be0bfa5f1e363804f6Praveen Chavan              memmove(buf + chromaOffset, buf + (width*height), chromaSize);
3459525cc9b815b0cb86e4fc02be0bfa5f1e363804f6Praveen Chavan          } else {
3460525cc9b815b0cb86e4fc02be0bfa5f1e363804f6Praveen Chavan             DEBUG_PRINT_ERROR("Failed to align Chroma. from %u to %u : \
3461525cc9b815b0cb86e4fc02be0bfa5f1e363804f6Praveen Chavan                 Insufficient bufferLen=%u v/s Required=%u",
3462525cc9b815b0cb86e4fc02be0bfa5f1e363804f6Praveen Chavan                 (width*height), chromaOffset, buffer->nAllocLen,
3463525cc9b815b0cb86e4fc02be0bfa5f1e363804f6Praveen Chavan                 chromaOffset+chromaSize);
3464525cc9b815b0cb86e4fc02be0bfa5f1e363804f6Praveen Chavan          }
3465525cc9b815b0cb86e4fc02be0bfa5f1e363804f6Praveen Chavan      }
346647e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
3467826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#ifdef _COPPER_
3468826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  if(dev_empty_buf(buffer, pmem_data_buf,nBufIndex,m_pInput_pmem[nBufIndex].fd) != true)
3469826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#else
3470826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  if(dev_empty_buf(buffer, pmem_data_buf,0,0) != true)
3471826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#endif
347247e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
347347e37c4428509524ee576920a98381f3e4872493Nick Pelly    DEBUG_PRINT_ERROR("\nERROR: ETBProxy: dev_empty_buf failed");
3474826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#ifdef _ANDROID_ICS_
3475826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    omx_release_meta_buffer(buffer);
3476826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#endif
3477826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    post_event ((unsigned int)buffer,0,OMX_COMPONENT_GENERATE_EBD);
347847e37c4428509524ee576920a98381f3e4872493Nick Pelly    /*Generate an async error and move to invalid state*/
347947e37c4428509524ee576920a98381f3e4872493Nick Pelly    pending_input_buffers--;
348047e37c4428509524ee576920a98381f3e4872493Nick Pelly    return OMX_ErrorBadParameter;
348147e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
348247e37c4428509524ee576920a98381f3e4872493Nick Pelly
348347e37c4428509524ee576920a98381f3e4872493Nick Pelly  return ret;
348447e37c4428509524ee576920a98381f3e4872493Nick Pelly}
348547e37c4428509524ee576920a98381f3e4872493Nick Pelly
348647e37c4428509524ee576920a98381f3e4872493Nick Pelly/* ======================================================================
348747e37c4428509524ee576920a98381f3e4872493Nick PellyFUNCTION
348847e37c4428509524ee576920a98381f3e4872493Nick Pelly  omx_video::FillThisBuffer
348947e37c4428509524ee576920a98381f3e4872493Nick Pelly
349047e37c4428509524ee576920a98381f3e4872493Nick PellyDESCRIPTION
349147e37c4428509524ee576920a98381f3e4872493Nick Pelly  IL client uses this method to release the frame buffer
349247e37c4428509524ee576920a98381f3e4872493Nick Pelly  after displaying them.
349347e37c4428509524ee576920a98381f3e4872493Nick Pelly
349447e37c4428509524ee576920a98381f3e4872493Nick PellyPARAMETERS
349547e37c4428509524ee576920a98381f3e4872493Nick Pelly  None.
349647e37c4428509524ee576920a98381f3e4872493Nick Pelly
349747e37c4428509524ee576920a98381f3e4872493Nick PellyRETURN VALUE
349847e37c4428509524ee576920a98381f3e4872493Nick Pelly  true/false
349947e37c4428509524ee576920a98381f3e4872493Nick Pelly
350047e37c4428509524ee576920a98381f3e4872493Nick Pelly========================================================================== */
350147e37c4428509524ee576920a98381f3e4872493Nick PellyOMX_ERRORTYPE  omx_video::fill_this_buffer(OMX_IN OMX_HANDLETYPE  hComp,
350247e37c4428509524ee576920a98381f3e4872493Nick Pelly                                           OMX_IN OMX_BUFFERHEADERTYPE* buffer)
350347e37c4428509524ee576920a98381f3e4872493Nick Pelly{
350447e37c4428509524ee576920a98381f3e4872493Nick Pelly  DEBUG_PRINT_LOW("\n FTB: buffer->pBuffer[%p]\n", buffer->pBuffer);
350547e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(m_state == OMX_StateInvalid)
350647e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
350747e37c4428509524ee576920a98381f3e4872493Nick Pelly    DEBUG_PRINT_ERROR("ERROR: FTB in Invalid State\n");
350847e37c4428509524ee576920a98381f3e4872493Nick Pelly    return OMX_ErrorInvalidState;
350947e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
351047e37c4428509524ee576920a98381f3e4872493Nick Pelly
351147e37c4428509524ee576920a98381f3e4872493Nick Pelly  if (buffer == NULL ||(buffer->nSize != sizeof(OMX_BUFFERHEADERTYPE)))
351247e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
351347e37c4428509524ee576920a98381f3e4872493Nick Pelly    DEBUG_PRINT_ERROR("ERROR: omx_video::ftb-->Invalid buffer or size\n");
351447e37c4428509524ee576920a98381f3e4872493Nick Pelly    return OMX_ErrorBadParameter;
351547e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
351647e37c4428509524ee576920a98381f3e4872493Nick Pelly
351747e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(buffer->nVersion.nVersion != OMX_SPEC_VERSION)
351847e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
351947e37c4428509524ee576920a98381f3e4872493Nick Pelly    DEBUG_PRINT_ERROR("ERROR: omx_video::ftb-->OMX Version Invalid\n");
352047e37c4428509524ee576920a98381f3e4872493Nick Pelly    return OMX_ErrorVersionMismatch;
352147e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
352247e37c4428509524ee576920a98381f3e4872493Nick Pelly
352347e37c4428509524ee576920a98381f3e4872493Nick Pelly  if (buffer->nOutputPortIndex != (OMX_U32)PORT_INDEX_OUT)
352447e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
352547e37c4428509524ee576920a98381f3e4872493Nick Pelly    DEBUG_PRINT_ERROR("ERROR: omx_video::ftb-->Bad port index\n");
352647e37c4428509524ee576920a98381f3e4872493Nick Pelly    return OMX_ErrorBadPortIndex;
352747e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
352847e37c4428509524ee576920a98381f3e4872493Nick Pelly
352947e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(!m_sOutPortDef.bEnabled)
353047e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
353147e37c4428509524ee576920a98381f3e4872493Nick Pelly    DEBUG_PRINT_ERROR("ERROR: omx_video::ftb-->port is disabled\n");
353247e37c4428509524ee576920a98381f3e4872493Nick Pelly    return OMX_ErrorIncorrectStateOperation;
353347e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
353447e37c4428509524ee576920a98381f3e4872493Nick Pelly
353547e37c4428509524ee576920a98381f3e4872493Nick Pelly  post_event((unsigned) hComp, (unsigned)buffer,OMX_COMPONENT_GENERATE_FTB);
353647e37c4428509524ee576920a98381f3e4872493Nick Pelly  return OMX_ErrorNone;
353747e37c4428509524ee576920a98381f3e4872493Nick Pelly}
353847e37c4428509524ee576920a98381f3e4872493Nick Pelly
353947e37c4428509524ee576920a98381f3e4872493Nick Pelly/* ======================================================================
354047e37c4428509524ee576920a98381f3e4872493Nick PellyFUNCTION
354147e37c4428509524ee576920a98381f3e4872493Nick Pelly  omx_video::fill_this_buffer_proxy
354247e37c4428509524ee576920a98381f3e4872493Nick Pelly
354347e37c4428509524ee576920a98381f3e4872493Nick PellyDESCRIPTION
354447e37c4428509524ee576920a98381f3e4872493Nick Pelly  IL client uses this method to release the frame buffer
354547e37c4428509524ee576920a98381f3e4872493Nick Pelly  after displaying them.
354647e37c4428509524ee576920a98381f3e4872493Nick Pelly
354747e37c4428509524ee576920a98381f3e4872493Nick PellyPARAMETERS
354847e37c4428509524ee576920a98381f3e4872493Nick Pelly  None.
354947e37c4428509524ee576920a98381f3e4872493Nick Pelly
355047e37c4428509524ee576920a98381f3e4872493Nick PellyRETURN VALUE
355147e37c4428509524ee576920a98381f3e4872493Nick Pelly  true/false
355247e37c4428509524ee576920a98381f3e4872493Nick Pelly
355347e37c4428509524ee576920a98381f3e4872493Nick Pelly========================================================================== */
355447e37c4428509524ee576920a98381f3e4872493Nick PellyOMX_ERRORTYPE  omx_video::fill_this_buffer_proxy(
355547e37c4428509524ee576920a98381f3e4872493Nick Pelly                                                OMX_IN OMX_HANDLETYPE        hComp,
355647e37c4428509524ee576920a98381f3e4872493Nick Pelly                                                OMX_IN OMX_BUFFERHEADERTYPE* bufferAdd)
355747e37c4428509524ee576920a98381f3e4872493Nick Pelly{
355847e37c4428509524ee576920a98381f3e4872493Nick Pelly  OMX_U8 *pmem_data_buf = NULL;
355947e37c4428509524ee576920a98381f3e4872493Nick Pelly  OMX_ERRORTYPE nRet = OMX_ErrorNone;
356047e37c4428509524ee576920a98381f3e4872493Nick Pelly
356147e37c4428509524ee576920a98381f3e4872493Nick Pelly  DEBUG_PRINT_LOW("\n FTBProxy: bufferAdd->pBuffer[%p]\n", bufferAdd->pBuffer);
356247e37c4428509524ee576920a98381f3e4872493Nick Pelly
356347e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(bufferAdd == NULL || ((bufferAdd - m_out_mem_ptr) >= m_sOutPortDef.nBufferCountActual) )
356447e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
356547e37c4428509524ee576920a98381f3e4872493Nick Pelly    DEBUG_PRINT_ERROR("\nERROR: FTBProxy: Invalid i/p params\n");
356647e37c4428509524ee576920a98381f3e4872493Nick Pelly    return OMX_ErrorBadParameter;
356747e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
356847e37c4428509524ee576920a98381f3e4872493Nick Pelly
356947e37c4428509524ee576920a98381f3e4872493Nick Pelly  pending_output_buffers++;
357047e37c4428509524ee576920a98381f3e4872493Nick Pelly  /*Return back the output buffer to client*/
357147e37c4428509524ee576920a98381f3e4872493Nick Pelly  if( m_sOutPortDef.bEnabled != OMX_TRUE || output_flush_progress == true)
357247e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
357347e37c4428509524ee576920a98381f3e4872493Nick Pelly    DEBUG_PRINT_LOW("\n o/p port is Disabled or Flush in Progress");
357447e37c4428509524ee576920a98381f3e4872493Nick Pelly    post_event ((unsigned int)bufferAdd,0,
357547e37c4428509524ee576920a98381f3e4872493Nick Pelly                OMX_COMPONENT_GENERATE_FBD);
357647e37c4428509524ee576920a98381f3e4872493Nick Pelly    return OMX_ErrorNone;
357747e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
357847e37c4428509524ee576920a98381f3e4872493Nick Pelly
357947e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(output_use_buffer && !m_use_output_pmem)
358047e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
358147e37c4428509524ee576920a98381f3e4872493Nick Pelly    DEBUG_PRINT_LOW("\n Heap UseBuffer case");
358247e37c4428509524ee576920a98381f3e4872493Nick Pelly    pmem_data_buf = (OMX_U8 *)m_pOutput_pmem[bufferAdd - m_out_mem_ptr].buffer;
358347e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
358447e37c4428509524ee576920a98381f3e4872493Nick Pelly
3585826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  if(dev_fill_buf(bufferAdd, pmem_data_buf,(bufferAdd - m_out_mem_ptr),m_pOutput_pmem[bufferAdd - m_out_mem_ptr].fd) != true)
358647e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
358747e37c4428509524ee576920a98381f3e4872493Nick Pelly    DEBUG_PRINT_ERROR("\nERROR: dev_fill_buf() Failed");
3588826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    post_event ((unsigned int)bufferAdd,0,OMX_COMPONENT_GENERATE_FBD);
358947e37c4428509524ee576920a98381f3e4872493Nick Pelly    pending_output_buffers--;
359047e37c4428509524ee576920a98381f3e4872493Nick Pelly    return OMX_ErrorBadParameter;
359147e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
359247e37c4428509524ee576920a98381f3e4872493Nick Pelly
359347e37c4428509524ee576920a98381f3e4872493Nick Pelly  return OMX_ErrorNone;
359447e37c4428509524ee576920a98381f3e4872493Nick Pelly}
359547e37c4428509524ee576920a98381f3e4872493Nick Pelly
359647e37c4428509524ee576920a98381f3e4872493Nick Pelly/* ======================================================================
359747e37c4428509524ee576920a98381f3e4872493Nick PellyFUNCTION
359847e37c4428509524ee576920a98381f3e4872493Nick Pelly  omx_video::SetCallbacks
359947e37c4428509524ee576920a98381f3e4872493Nick Pelly
360047e37c4428509524ee576920a98381f3e4872493Nick PellyDESCRIPTION
360147e37c4428509524ee576920a98381f3e4872493Nick Pelly  Set the callbacks.
360247e37c4428509524ee576920a98381f3e4872493Nick Pelly
360347e37c4428509524ee576920a98381f3e4872493Nick PellyPARAMETERS
360447e37c4428509524ee576920a98381f3e4872493Nick Pelly  None.
360547e37c4428509524ee576920a98381f3e4872493Nick Pelly
360647e37c4428509524ee576920a98381f3e4872493Nick PellyRETURN VALUE
360747e37c4428509524ee576920a98381f3e4872493Nick Pelly  OMX Error None if everything successful.
360847e37c4428509524ee576920a98381f3e4872493Nick Pelly
360947e37c4428509524ee576920a98381f3e4872493Nick Pelly========================================================================== */
361047e37c4428509524ee576920a98381f3e4872493Nick PellyOMX_ERRORTYPE  omx_video::set_callbacks(OMX_IN OMX_HANDLETYPE        hComp,
361147e37c4428509524ee576920a98381f3e4872493Nick Pelly                                        OMX_IN OMX_CALLBACKTYPE* callbacks,
361247e37c4428509524ee576920a98381f3e4872493Nick Pelly                                        OMX_IN OMX_PTR             appData)
361347e37c4428509524ee576920a98381f3e4872493Nick Pelly{
361447e37c4428509524ee576920a98381f3e4872493Nick Pelly
361547e37c4428509524ee576920a98381f3e4872493Nick Pelly  m_pCallbacks       = *callbacks;
361647e37c4428509524ee576920a98381f3e4872493Nick Pelly  DEBUG_PRINT_LOW("\n Callbacks Set %p %p %p",m_pCallbacks.EmptyBufferDone,\
361747e37c4428509524ee576920a98381f3e4872493Nick Pelly               m_pCallbacks.EventHandler,m_pCallbacks.FillBufferDone);
361847e37c4428509524ee576920a98381f3e4872493Nick Pelly  m_app_data =    appData;
361947e37c4428509524ee576920a98381f3e4872493Nick Pelly  return OMX_ErrorNotImplemented;
362047e37c4428509524ee576920a98381f3e4872493Nick Pelly}
362147e37c4428509524ee576920a98381f3e4872493Nick Pelly
362247e37c4428509524ee576920a98381f3e4872493Nick Pelly
362347e37c4428509524ee576920a98381f3e4872493Nick Pelly/* ======================================================================
362447e37c4428509524ee576920a98381f3e4872493Nick PellyFUNCTION
362547e37c4428509524ee576920a98381f3e4872493Nick Pelly  omx_venc::UseEGLImage
362647e37c4428509524ee576920a98381f3e4872493Nick Pelly
362747e37c4428509524ee576920a98381f3e4872493Nick PellyDESCRIPTION
362847e37c4428509524ee576920a98381f3e4872493Nick Pelly  OMX Use EGL Image method implementation <TBD>.
362947e37c4428509524ee576920a98381f3e4872493Nick Pelly
363047e37c4428509524ee576920a98381f3e4872493Nick PellyPARAMETERS
363147e37c4428509524ee576920a98381f3e4872493Nick Pelly  <TBD>.
363247e37c4428509524ee576920a98381f3e4872493Nick Pelly
363347e37c4428509524ee576920a98381f3e4872493Nick PellyRETURN VALUE
363447e37c4428509524ee576920a98381f3e4872493Nick Pelly  Not Implemented error.
363547e37c4428509524ee576920a98381f3e4872493Nick Pelly
363647e37c4428509524ee576920a98381f3e4872493Nick Pelly========================================================================== */
363747e37c4428509524ee576920a98381f3e4872493Nick PellyOMX_ERRORTYPE  omx_video::use_EGL_image(OMX_IN OMX_HANDLETYPE                hComp,
363847e37c4428509524ee576920a98381f3e4872493Nick Pelly                                        OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr,
363947e37c4428509524ee576920a98381f3e4872493Nick Pelly                                        OMX_IN OMX_U32                        port,
364047e37c4428509524ee576920a98381f3e4872493Nick Pelly                                        OMX_IN OMX_PTR                     appData,
364147e37c4428509524ee576920a98381f3e4872493Nick Pelly                                        OMX_IN void*                      eglImage)
364247e37c4428509524ee576920a98381f3e4872493Nick Pelly{
364347e37c4428509524ee576920a98381f3e4872493Nick Pelly  DEBUG_PRINT_ERROR("ERROR: use_EGL_image:  Not Implemented \n");
364447e37c4428509524ee576920a98381f3e4872493Nick Pelly  return OMX_ErrorNotImplemented;
364547e37c4428509524ee576920a98381f3e4872493Nick Pelly}
364647e37c4428509524ee576920a98381f3e4872493Nick Pelly
364747e37c4428509524ee576920a98381f3e4872493Nick Pelly/* ======================================================================
364847e37c4428509524ee576920a98381f3e4872493Nick PellyFUNCTION
364947e37c4428509524ee576920a98381f3e4872493Nick Pelly  omx_venc::ComponentRoleEnum
365047e37c4428509524ee576920a98381f3e4872493Nick Pelly
365147e37c4428509524ee576920a98381f3e4872493Nick PellyDESCRIPTION
365247e37c4428509524ee576920a98381f3e4872493Nick Pelly  OMX Component Role Enum method implementation.
365347e37c4428509524ee576920a98381f3e4872493Nick Pelly
365447e37c4428509524ee576920a98381f3e4872493Nick PellyPARAMETERS
365547e37c4428509524ee576920a98381f3e4872493Nick Pelly  <TBD>.
365647e37c4428509524ee576920a98381f3e4872493Nick Pelly
365747e37c4428509524ee576920a98381f3e4872493Nick PellyRETURN VALUE
365847e37c4428509524ee576920a98381f3e4872493Nick Pelly  OMX Error None if everything is successful.
365947e37c4428509524ee576920a98381f3e4872493Nick Pelly========================================================================== */
366047e37c4428509524ee576920a98381f3e4872493Nick PellyOMX_ERRORTYPE  omx_video::component_role_enum(OMX_IN OMX_HANDLETYPE hComp,
366147e37c4428509524ee576920a98381f3e4872493Nick Pelly                                              OMX_OUT OMX_U8*        role,
366247e37c4428509524ee576920a98381f3e4872493Nick Pelly                                              OMX_IN OMX_U32        index)
366347e37c4428509524ee576920a98381f3e4872493Nick Pelly{
366447e37c4428509524ee576920a98381f3e4872493Nick Pelly  OMX_ERRORTYPE eRet = OMX_ErrorNone;
366547e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(!strncmp((char*)m_nkind, "OMX.qcom.video.decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE))
366647e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
366747e37c4428509524ee576920a98381f3e4872493Nick Pelly    if((0 == index) && role)
366847e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
3669826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      strlcpy((char *)role, "video_decoder.mpeg4",OMX_MAX_STRINGNAME_SIZE);
367047e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_LOW("component_role_enum: role %s\n",role);
367147e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
367247e37c4428509524ee576920a98381f3e4872493Nick Pelly    else
367347e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
367447e37c4428509524ee576920a98381f3e4872493Nick Pelly      eRet = OMX_ErrorNoMore;
367547e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
367647e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
367747e37c4428509524ee576920a98381f3e4872493Nick Pelly  else if(!strncmp((char*)m_nkind, "OMX.qcom.video.decoder.h263",OMX_MAX_STRINGNAME_SIZE))
367847e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
367947e37c4428509524ee576920a98381f3e4872493Nick Pelly    if((0 == index) && role)
368047e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
3681826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      strlcpy((char *)role, "video_decoder.h263",OMX_MAX_STRINGNAME_SIZE);
368247e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_LOW("component_role_enum: role %s\n",role);
368347e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
368447e37c4428509524ee576920a98381f3e4872493Nick Pelly    else
368547e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
368647e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_ERROR("\nERROR: No more roles \n");
368747e37c4428509524ee576920a98381f3e4872493Nick Pelly      eRet = OMX_ErrorNoMore;
368847e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
368947e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
369047e37c4428509524ee576920a98381f3e4872493Nick Pelly  else if(!strncmp((char*)m_nkind, "OMX.qcom.video.decoder.avc",OMX_MAX_STRINGNAME_SIZE))
369147e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
369247e37c4428509524ee576920a98381f3e4872493Nick Pelly    if((0 == index) && role)
369347e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
3694826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      strlcpy((char *)role, "video_decoder.avc",OMX_MAX_STRINGNAME_SIZE);
369547e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_LOW("component_role_enum: role %s\n",role);
369647e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
369747e37c4428509524ee576920a98381f3e4872493Nick Pelly    else
369847e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
369947e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_ERROR("\nERROR: No more roles \n");
370047e37c4428509524ee576920a98381f3e4872493Nick Pelly      eRet = OMX_ErrorNoMore;
370147e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
370247e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
370347e37c4428509524ee576920a98381f3e4872493Nick Pelly  else if(!strncmp((char*)m_nkind, "OMX.qcom.video.decoder.vc1",OMX_MAX_STRINGNAME_SIZE))
370447e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
370547e37c4428509524ee576920a98381f3e4872493Nick Pelly    if((0 == index) && role)
370647e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
3707826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      strlcpy((char *)role, "video_decoder.vc1",OMX_MAX_STRINGNAME_SIZE);
370847e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_LOW("component_role_enum: role %s\n",role);
370947e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
371047e37c4428509524ee576920a98381f3e4872493Nick Pelly    else
371147e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
371247e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_ERROR("\nERROR: No more roles \n");
371347e37c4428509524ee576920a98381f3e4872493Nick Pelly      eRet = OMX_ErrorNoMore;
371447e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
371547e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
371647e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(!strncmp((char*)m_nkind, "OMX.qcom.video.encoder.mpeg4",OMX_MAX_STRINGNAME_SIZE))
371747e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
371847e37c4428509524ee576920a98381f3e4872493Nick Pelly    if((0 == index) && role)
371947e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
3720826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      strlcpy((char *)role, "video_encoder.mpeg4",OMX_MAX_STRINGNAME_SIZE);
372147e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_LOW("component_role_enum: role %s\n",role);
372247e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
372347e37c4428509524ee576920a98381f3e4872493Nick Pelly    else
372447e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
372547e37c4428509524ee576920a98381f3e4872493Nick Pelly      eRet = OMX_ErrorNoMore;
372647e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
372747e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
372847e37c4428509524ee576920a98381f3e4872493Nick Pelly  else if(!strncmp((char*)m_nkind, "OMX.qcom.video.encoder.h263",OMX_MAX_STRINGNAME_SIZE))
372947e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
373047e37c4428509524ee576920a98381f3e4872493Nick Pelly    if((0 == index) && role)
373147e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
3732826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      strlcpy((char *)role, "video_encoder.h263",OMX_MAX_STRINGNAME_SIZE);
373347e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_LOW("component_role_enum: role %s\n",role);
373447e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
373547e37c4428509524ee576920a98381f3e4872493Nick Pelly    else
373647e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
373747e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_ERROR("\nERROR: No more roles \n");
373847e37c4428509524ee576920a98381f3e4872493Nick Pelly      eRet = OMX_ErrorNoMore;
373947e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
374047e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
374147e37c4428509524ee576920a98381f3e4872493Nick Pelly  else if(!strncmp((char*)m_nkind, "OMX.qcom.video.encoder.avc",OMX_MAX_STRINGNAME_SIZE))
374247e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
374347e37c4428509524ee576920a98381f3e4872493Nick Pelly    if((0 == index) && role)
374447e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
3745826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      strlcpy((char *)role, "video_encoder.avc",OMX_MAX_STRINGNAME_SIZE);
374647e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_LOW("component_role_enum: role %s\n",role);
374747e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
374847e37c4428509524ee576920a98381f3e4872493Nick Pelly    else
374947e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
375047e37c4428509524ee576920a98381f3e4872493Nick Pelly      DEBUG_PRINT_ERROR("\nERROR: No more roles \n");
375147e37c4428509524ee576920a98381f3e4872493Nick Pelly      eRet = OMX_ErrorNoMore;
375247e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
375347e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
375447e37c4428509524ee576920a98381f3e4872493Nick Pelly  else
375547e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
375647e37c4428509524ee576920a98381f3e4872493Nick Pelly    DEBUG_PRINT_ERROR("\nERROR: Querying Role on Unknown Component\n");
375747e37c4428509524ee576920a98381f3e4872493Nick Pelly    eRet = OMX_ErrorInvalidComponentName;
375847e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
375947e37c4428509524ee576920a98381f3e4872493Nick Pelly  return eRet;
376047e37c4428509524ee576920a98381f3e4872493Nick Pelly}
376147e37c4428509524ee576920a98381f3e4872493Nick Pelly
376247e37c4428509524ee576920a98381f3e4872493Nick Pelly
376347e37c4428509524ee576920a98381f3e4872493Nick Pelly
376447e37c4428509524ee576920a98381f3e4872493Nick Pelly
376547e37c4428509524ee576920a98381f3e4872493Nick Pelly/* ======================================================================
376647e37c4428509524ee576920a98381f3e4872493Nick PellyFUNCTION
376747e37c4428509524ee576920a98381f3e4872493Nick Pelly  omx_venc::AllocateDone
376847e37c4428509524ee576920a98381f3e4872493Nick Pelly
376947e37c4428509524ee576920a98381f3e4872493Nick PellyDESCRIPTION
377047e37c4428509524ee576920a98381f3e4872493Nick Pelly  Checks if entire buffer pool is allocated by IL Client or not.
377147e37c4428509524ee576920a98381f3e4872493Nick Pelly  Need this to move to IDLE state.
377247e37c4428509524ee576920a98381f3e4872493Nick Pelly
377347e37c4428509524ee576920a98381f3e4872493Nick PellyPARAMETERS
377447e37c4428509524ee576920a98381f3e4872493Nick Pelly  None.
377547e37c4428509524ee576920a98381f3e4872493Nick Pelly
377647e37c4428509524ee576920a98381f3e4872493Nick PellyRETURN VALUE
377747e37c4428509524ee576920a98381f3e4872493Nick Pelly  true/false.
377847e37c4428509524ee576920a98381f3e4872493Nick Pelly
377947e37c4428509524ee576920a98381f3e4872493Nick Pelly========================================================================== */
378047e37c4428509524ee576920a98381f3e4872493Nick Pellybool omx_video::allocate_done(void)
378147e37c4428509524ee576920a98381f3e4872493Nick Pelly{
378247e37c4428509524ee576920a98381f3e4872493Nick Pelly  bool bRet = false;
378347e37c4428509524ee576920a98381f3e4872493Nick Pelly  bool bRet_In = false;
378447e37c4428509524ee576920a98381f3e4872493Nick Pelly  bool bRet_Out = false;
378547e37c4428509524ee576920a98381f3e4872493Nick Pelly
378647e37c4428509524ee576920a98381f3e4872493Nick Pelly  bRet_In = allocate_input_done();
378747e37c4428509524ee576920a98381f3e4872493Nick Pelly  bRet_Out = allocate_output_done();
378847e37c4428509524ee576920a98381f3e4872493Nick Pelly
378947e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(bRet_In && bRet_Out)
379047e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
379147e37c4428509524ee576920a98381f3e4872493Nick Pelly    bRet = true;
379247e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
379347e37c4428509524ee576920a98381f3e4872493Nick Pelly
379447e37c4428509524ee576920a98381f3e4872493Nick Pelly  return bRet;
379547e37c4428509524ee576920a98381f3e4872493Nick Pelly}
379647e37c4428509524ee576920a98381f3e4872493Nick Pelly/* ======================================================================
379747e37c4428509524ee576920a98381f3e4872493Nick PellyFUNCTION
379847e37c4428509524ee576920a98381f3e4872493Nick Pelly  omx_venc::AllocateInputDone
379947e37c4428509524ee576920a98381f3e4872493Nick Pelly
380047e37c4428509524ee576920a98381f3e4872493Nick PellyDESCRIPTION
380147e37c4428509524ee576920a98381f3e4872493Nick Pelly  Checks if I/P buffer pool is allocated by IL Client or not.
380247e37c4428509524ee576920a98381f3e4872493Nick Pelly
380347e37c4428509524ee576920a98381f3e4872493Nick PellyPARAMETERS
380447e37c4428509524ee576920a98381f3e4872493Nick Pelly  None.
380547e37c4428509524ee576920a98381f3e4872493Nick Pelly
380647e37c4428509524ee576920a98381f3e4872493Nick PellyRETURN VALUE
380747e37c4428509524ee576920a98381f3e4872493Nick Pelly  true/false.
380847e37c4428509524ee576920a98381f3e4872493Nick Pelly
380947e37c4428509524ee576920a98381f3e4872493Nick Pelly========================================================================== */
381047e37c4428509524ee576920a98381f3e4872493Nick Pellybool omx_video::allocate_input_done(void)
381147e37c4428509524ee576920a98381f3e4872493Nick Pelly{
381247e37c4428509524ee576920a98381f3e4872493Nick Pelly  bool bRet = false;
381347e37c4428509524ee576920a98381f3e4872493Nick Pelly  unsigned i=0;
381447e37c4428509524ee576920a98381f3e4872493Nick Pelly
381547e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(m_inp_mem_ptr == NULL)
381647e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
381747e37c4428509524ee576920a98381f3e4872493Nick Pelly    return bRet;
381847e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
381947e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(m_inp_mem_ptr )
382047e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
382147e37c4428509524ee576920a98381f3e4872493Nick Pelly    for(;i<m_sInPortDef.nBufferCountActual;i++)
382247e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
382347e37c4428509524ee576920a98381f3e4872493Nick Pelly      if(BITMASK_ABSENT(&m_inp_bm_count,i))
382447e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
382547e37c4428509524ee576920a98381f3e4872493Nick Pelly        break;
382647e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
382747e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
382847e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
382947e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(i==m_sInPortDef.nBufferCountActual)
383047e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
383147e37c4428509524ee576920a98381f3e4872493Nick Pelly    bRet = true;
383247e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
383347e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(i==m_sInPortDef.nBufferCountActual && m_sInPortDef.bEnabled)
383447e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
383547e37c4428509524ee576920a98381f3e4872493Nick Pelly    m_sInPortDef.bPopulated = OMX_TRUE;
383647e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
383747e37c4428509524ee576920a98381f3e4872493Nick Pelly  return bRet;
383847e37c4428509524ee576920a98381f3e4872493Nick Pelly}
383947e37c4428509524ee576920a98381f3e4872493Nick Pelly/* ======================================================================
384047e37c4428509524ee576920a98381f3e4872493Nick PellyFUNCTION
384147e37c4428509524ee576920a98381f3e4872493Nick Pelly  omx_venc::AllocateOutputDone
384247e37c4428509524ee576920a98381f3e4872493Nick Pelly
384347e37c4428509524ee576920a98381f3e4872493Nick PellyDESCRIPTION
384447e37c4428509524ee576920a98381f3e4872493Nick Pelly  Checks if entire O/P buffer pool is allocated by IL Client or not.
384547e37c4428509524ee576920a98381f3e4872493Nick Pelly
384647e37c4428509524ee576920a98381f3e4872493Nick PellyPARAMETERS
384747e37c4428509524ee576920a98381f3e4872493Nick Pelly  None.
384847e37c4428509524ee576920a98381f3e4872493Nick Pelly
384947e37c4428509524ee576920a98381f3e4872493Nick PellyRETURN VALUE
385047e37c4428509524ee576920a98381f3e4872493Nick Pelly  true/false.
385147e37c4428509524ee576920a98381f3e4872493Nick Pelly
385247e37c4428509524ee576920a98381f3e4872493Nick Pelly========================================================================== */
385347e37c4428509524ee576920a98381f3e4872493Nick Pellybool omx_video::allocate_output_done(void)
385447e37c4428509524ee576920a98381f3e4872493Nick Pelly{
385547e37c4428509524ee576920a98381f3e4872493Nick Pelly  bool bRet = false;
385647e37c4428509524ee576920a98381f3e4872493Nick Pelly  unsigned j=0;
385747e37c4428509524ee576920a98381f3e4872493Nick Pelly
385847e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(m_out_mem_ptr == NULL)
385947e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
386047e37c4428509524ee576920a98381f3e4872493Nick Pelly    return bRet;
386147e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
386247e37c4428509524ee576920a98381f3e4872493Nick Pelly
386347e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(m_out_mem_ptr )
386447e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
386547e37c4428509524ee576920a98381f3e4872493Nick Pelly    for(;j<m_sOutPortDef.nBufferCountActual;j++)
386647e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
386747e37c4428509524ee576920a98381f3e4872493Nick Pelly      if(BITMASK_ABSENT(&m_out_bm_count,j))
386847e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
386947e37c4428509524ee576920a98381f3e4872493Nick Pelly        break;
387047e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
387147e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
387247e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
387347e37c4428509524ee576920a98381f3e4872493Nick Pelly
387447e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(j==m_sOutPortDef.nBufferCountActual)
387547e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
387647e37c4428509524ee576920a98381f3e4872493Nick Pelly    bRet = true;
387747e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
387847e37c4428509524ee576920a98381f3e4872493Nick Pelly
387947e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(j==m_sOutPortDef.nBufferCountActual && m_sOutPortDef.bEnabled)
388047e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
388147e37c4428509524ee576920a98381f3e4872493Nick Pelly    m_sOutPortDef.bPopulated = OMX_TRUE;
388247e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
388347e37c4428509524ee576920a98381f3e4872493Nick Pelly  return bRet;
388447e37c4428509524ee576920a98381f3e4872493Nick Pelly}
388547e37c4428509524ee576920a98381f3e4872493Nick Pelly
388647e37c4428509524ee576920a98381f3e4872493Nick Pelly/* ======================================================================
388747e37c4428509524ee576920a98381f3e4872493Nick PellyFUNCTION
388847e37c4428509524ee576920a98381f3e4872493Nick Pelly  omx_venc::ReleaseDone
388947e37c4428509524ee576920a98381f3e4872493Nick Pelly
389047e37c4428509524ee576920a98381f3e4872493Nick PellyDESCRIPTION
389147e37c4428509524ee576920a98381f3e4872493Nick Pelly  Checks if IL client has released all the buffers.
389247e37c4428509524ee576920a98381f3e4872493Nick Pelly
389347e37c4428509524ee576920a98381f3e4872493Nick PellyPARAMETERS
389447e37c4428509524ee576920a98381f3e4872493Nick Pelly  None.
389547e37c4428509524ee576920a98381f3e4872493Nick Pelly
389647e37c4428509524ee576920a98381f3e4872493Nick PellyRETURN VALUE
389747e37c4428509524ee576920a98381f3e4872493Nick Pelly  true/false
389847e37c4428509524ee576920a98381f3e4872493Nick Pelly
389947e37c4428509524ee576920a98381f3e4872493Nick Pelly========================================================================== */
390047e37c4428509524ee576920a98381f3e4872493Nick Pellybool omx_video::release_done(void)
390147e37c4428509524ee576920a98381f3e4872493Nick Pelly{
390247e37c4428509524ee576920a98381f3e4872493Nick Pelly  bool bRet = false;
390347e37c4428509524ee576920a98381f3e4872493Nick Pelly  DEBUG_PRINT_LOW("Inside release_done()\n");
390447e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(release_input_done())
390547e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
390647e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(release_output_done())
390747e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
390847e37c4428509524ee576920a98381f3e4872493Nick Pelly      bRet = true;
390947e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
391047e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
391147e37c4428509524ee576920a98381f3e4872493Nick Pelly  return bRet;
391247e37c4428509524ee576920a98381f3e4872493Nick Pelly}
391347e37c4428509524ee576920a98381f3e4872493Nick Pelly
391447e37c4428509524ee576920a98381f3e4872493Nick Pelly
391547e37c4428509524ee576920a98381f3e4872493Nick Pelly/* ======================================================================
391647e37c4428509524ee576920a98381f3e4872493Nick PellyFUNCTION
391747e37c4428509524ee576920a98381f3e4872493Nick Pelly  omx_venc::ReleaseOutputDone
391847e37c4428509524ee576920a98381f3e4872493Nick Pelly
391947e37c4428509524ee576920a98381f3e4872493Nick PellyDESCRIPTION
392047e37c4428509524ee576920a98381f3e4872493Nick Pelly  Checks if IL client has released all the buffers.
392147e37c4428509524ee576920a98381f3e4872493Nick Pelly
392247e37c4428509524ee576920a98381f3e4872493Nick PellyPARAMETERS
392347e37c4428509524ee576920a98381f3e4872493Nick Pelly  None.
392447e37c4428509524ee576920a98381f3e4872493Nick Pelly
392547e37c4428509524ee576920a98381f3e4872493Nick PellyRETURN VALUE
392647e37c4428509524ee576920a98381f3e4872493Nick Pelly  true/false
392747e37c4428509524ee576920a98381f3e4872493Nick Pelly
392847e37c4428509524ee576920a98381f3e4872493Nick Pelly========================================================================== */
392947e37c4428509524ee576920a98381f3e4872493Nick Pellybool omx_video::release_output_done(void)
393047e37c4428509524ee576920a98381f3e4872493Nick Pelly{
393147e37c4428509524ee576920a98381f3e4872493Nick Pelly  bool bRet = false;
393247e37c4428509524ee576920a98381f3e4872493Nick Pelly  unsigned i=0,j=0;
393347e37c4428509524ee576920a98381f3e4872493Nick Pelly
393447e37c4428509524ee576920a98381f3e4872493Nick Pelly  DEBUG_PRINT_LOW("Inside release_output_done()\n");
393547e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(m_out_mem_ptr)
393647e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
393747e37c4428509524ee576920a98381f3e4872493Nick Pelly    for(;j<m_sOutPortDef.nBufferCountActual;j++)
393847e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
393947e37c4428509524ee576920a98381f3e4872493Nick Pelly      if(BITMASK_PRESENT(&m_out_bm_count,j))
394047e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
394147e37c4428509524ee576920a98381f3e4872493Nick Pelly        break;
394247e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
394347e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
394447e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(j==m_sOutPortDef.nBufferCountActual)
394547e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
394647e37c4428509524ee576920a98381f3e4872493Nick Pelly      bRet = true;
394747e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
394847e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
394947e37c4428509524ee576920a98381f3e4872493Nick Pelly  else
395047e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
395147e37c4428509524ee576920a98381f3e4872493Nick Pelly    bRet = true;
395247e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
395347e37c4428509524ee576920a98381f3e4872493Nick Pelly  return bRet;
395447e37c4428509524ee576920a98381f3e4872493Nick Pelly}
395547e37c4428509524ee576920a98381f3e4872493Nick Pelly/* ======================================================================
395647e37c4428509524ee576920a98381f3e4872493Nick PellyFUNCTION
395747e37c4428509524ee576920a98381f3e4872493Nick Pelly  omx_venc::ReleaseInputDone
395847e37c4428509524ee576920a98381f3e4872493Nick Pelly
395947e37c4428509524ee576920a98381f3e4872493Nick PellyDESCRIPTION
396047e37c4428509524ee576920a98381f3e4872493Nick Pelly  Checks if IL client has released all the buffers.
396147e37c4428509524ee576920a98381f3e4872493Nick Pelly
396247e37c4428509524ee576920a98381f3e4872493Nick PellyPARAMETERS
396347e37c4428509524ee576920a98381f3e4872493Nick Pelly  None.
396447e37c4428509524ee576920a98381f3e4872493Nick Pelly
396547e37c4428509524ee576920a98381f3e4872493Nick PellyRETURN VALUE
396647e37c4428509524ee576920a98381f3e4872493Nick Pelly  true/false
396747e37c4428509524ee576920a98381f3e4872493Nick Pelly
396847e37c4428509524ee576920a98381f3e4872493Nick Pelly========================================================================== */
396947e37c4428509524ee576920a98381f3e4872493Nick Pellybool omx_video::release_input_done(void)
397047e37c4428509524ee576920a98381f3e4872493Nick Pelly{
397147e37c4428509524ee576920a98381f3e4872493Nick Pelly  bool bRet = false;
397247e37c4428509524ee576920a98381f3e4872493Nick Pelly  unsigned i=0,j=0;
397347e37c4428509524ee576920a98381f3e4872493Nick Pelly
397447e37c4428509524ee576920a98381f3e4872493Nick Pelly  DEBUG_PRINT_LOW("Inside release_input_done()\n");
397547e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(m_inp_mem_ptr)
397647e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
397747e37c4428509524ee576920a98381f3e4872493Nick Pelly    for(;j<m_sInPortDef.nBufferCountActual;j++)
397847e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
397947e37c4428509524ee576920a98381f3e4872493Nick Pelly      if( BITMASK_PRESENT(&m_inp_bm_count,j))
398047e37c4428509524ee576920a98381f3e4872493Nick Pelly      {
398147e37c4428509524ee576920a98381f3e4872493Nick Pelly        break;
398247e37c4428509524ee576920a98381f3e4872493Nick Pelly      }
398347e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
398447e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(j==m_sInPortDef.nBufferCountActual)
398547e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
398647e37c4428509524ee576920a98381f3e4872493Nick Pelly      bRet = true;
398747e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
398847e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
398947e37c4428509524ee576920a98381f3e4872493Nick Pelly  else
399047e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
399147e37c4428509524ee576920a98381f3e4872493Nick Pelly    bRet = true;
399247e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
399347e37c4428509524ee576920a98381f3e4872493Nick Pelly  return bRet;
399447e37c4428509524ee576920a98381f3e4872493Nick Pelly}
399547e37c4428509524ee576920a98381f3e4872493Nick Pelly
399647e37c4428509524ee576920a98381f3e4872493Nick PellyOMX_ERRORTYPE omx_video::fill_buffer_done(OMX_HANDLETYPE hComp,
399747e37c4428509524ee576920a98381f3e4872493Nick Pelly                                          OMX_BUFFERHEADERTYPE * buffer)
399847e37c4428509524ee576920a98381f3e4872493Nick Pelly{
39997eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  DEBUG_PRINT_LOW("fill_buffer_done: buffer->pBuffer[%p], flags=0x%x size = %d",
40007eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George     buffer->pBuffer, buffer->nFlags,buffer->nFilledLen);
400147e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(buffer == NULL || ((buffer - m_out_mem_ptr) > m_sOutPortDef.nBufferCountActual))
400247e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
400347e37c4428509524ee576920a98381f3e4872493Nick Pelly    return OMX_ErrorBadParameter;
400447e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
400547e37c4428509524ee576920a98381f3e4872493Nick Pelly
400647e37c4428509524ee576920a98381f3e4872493Nick Pelly  pending_output_buffers--;
40077783f07680c4e868295efbd0cf55a1622a106522Deva Ramasubramanian  if(!secure_session)
40087783f07680c4e868295efbd0cf55a1622a106522Deva Ramasubramanian  {
40097783f07680c4e868295efbd0cf55a1622a106522Deva Ramasubramanian    extra_data_handle.create_extra_data(buffer);
40107783f07680c4e868295efbd0cf55a1622a106522Deva Ramasubramanian  }
401147e37c4428509524ee576920a98381f3e4872493Nick Pelly
40127783f07680c4e868295efbd0cf55a1622a106522Deva Ramasubramanian  if (!secure_session && m_sDebugSliceinfo) {
4013826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    if(buffer->nFlags & OMX_BUFFERFLAG_EXTRADATA) {
4014826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev       DEBUG_PRINT_HIGH("parsing extradata");
4015826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev       extra_data_handle.parse_extra_data(buffer);
4016826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    }
4017826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  }
401847e37c4428509524ee576920a98381f3e4872493Nick Pelly  /* For use buffer we need to copy the data */
401947e37c4428509524ee576920a98381f3e4872493Nick Pelly  if(m_pCallbacks.FillBufferDone)
402047e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
402147e37c4428509524ee576920a98381f3e4872493Nick Pelly    if(buffer->nFilledLen > 0)
402247e37c4428509524ee576920a98381f3e4872493Nick Pelly    {
402347e37c4428509524ee576920a98381f3e4872493Nick Pelly      m_fbd_count++;
4024826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev
4025826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#ifdef OUTPUT_BUFFER_LOG
4026826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      if(outputBufferFile1)
4027826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      {
4028826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        fwrite((const char *)buffer->pBuffer, buffer->nFilledLen, 1, outputBufferFile1);
4029826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      }
4030826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#endif
403147e37c4428509524ee576920a98381f3e4872493Nick Pelly    }
403247e37c4428509524ee576920a98381f3e4872493Nick Pelly    m_pCallbacks.FillBufferDone (hComp,m_app_data,buffer);
403347e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
403447e37c4428509524ee576920a98381f3e4872493Nick Pelly  else
403547e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
403647e37c4428509524ee576920a98381f3e4872493Nick Pelly    return OMX_ErrorBadParameter;
403747e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
403847e37c4428509524ee576920a98381f3e4872493Nick Pelly  return OMX_ErrorNone;
403947e37c4428509524ee576920a98381f3e4872493Nick Pelly}
404047e37c4428509524ee576920a98381f3e4872493Nick Pelly
404147e37c4428509524ee576920a98381f3e4872493Nick PellyOMX_ERRORTYPE omx_video::empty_buffer_done(OMX_HANDLETYPE         hComp,
404247e37c4428509524ee576920a98381f3e4872493Nick Pelly                                           OMX_BUFFERHEADERTYPE* buffer)
404347e37c4428509524ee576920a98381f3e4872493Nick Pelly{
40447eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  int buffer_index  = -1;
40457eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  int buffer_index_meta = -1;
40467eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George
40477eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  buffer_index = (buffer - m_inp_mem_ptr);
40487eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  buffer_index_meta = (buffer - meta_buffer_hdr);
40497eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  DEBUG_PRINT_LOW("\n empty_buffer_done: buffer[%p]", buffer);
40507eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  if(buffer == NULL ||
40517eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George     ((buffer_index > m_sInPortDef.nBufferCountActual) &&
40527eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      (buffer_index_meta > m_sInPortDef.nBufferCountActual)))
405347e37c4428509524ee576920a98381f3e4872493Nick Pelly  {
40547eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    DEBUG_PRINT_ERROR("\n ERROR in empty_buffer_done due to index buffer");
405547e37c4428509524ee576920a98381f3e4872493Nick Pelly    return OMX_ErrorBadParameter;
405647e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
405747e37c4428509524ee576920a98381f3e4872493Nick Pelly
405847e37c4428509524ee576920a98381f3e4872493Nick Pelly  pending_input_buffers--;
4059826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev
40607eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  if(mUseProxyColorFormat && (buffer_index < m_sInPortDef.nBufferCountActual)) {
40617eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    if(!pdest_frame) {
40627eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      pdest_frame = buffer;
40637eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      DEBUG_PRINT_LOW("\n empty_buffer_done pdest_frame address is %p",pdest_frame);
40647eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      return push_input_buffer(hComp);
40657eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George
40667eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    } else {
40677eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      DEBUG_PRINT_LOW("\n empty_buffer_done insert address is %p",buffer);
40687eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      if (!m_opq_pmem_q.insert_entry((unsigned int)buffer, 0, 0)) {
40697eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George        DEBUG_PRINT_ERROR("\n empty_buffer_done: pmem queue is full");
40707eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George        return OMX_ErrorBadParameter;
40717eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      }
40727eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    }
40737eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  } else if(m_pCallbacks.EmptyBufferDone) {
407447e37c4428509524ee576920a98381f3e4872493Nick Pelly    m_pCallbacks.EmptyBufferDone(hComp ,m_app_data, buffer);
407547e37c4428509524ee576920a98381f3e4872493Nick Pelly  }
407647e37c4428509524ee576920a98381f3e4872493Nick Pelly  return OMX_ErrorNone;
407747e37c4428509524ee576920a98381f3e4872493Nick Pelly}
4078826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev
4079826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchevvoid omx_video::complete_pending_buffer_done_cbs()
4080826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev{
4081826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  unsigned p1;
4082826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  unsigned p2;
4083826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  unsigned ident;
4084826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  omx_cmd_queue tmp_q, pending_bd_q;
4085826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  pthread_mutex_lock(&m_lock);
4086826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  // pop all pending GENERATE FDB from ftb queue
4087826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  while (m_ftb_q.m_size)
4088826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  {
4089826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    m_ftb_q.pop_entry(&p1,&p2,&ident);
4090826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    if(ident == OMX_COMPONENT_GENERATE_FBD)
4091826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    {
4092826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      pending_bd_q.insert_entry(p1,p2,ident);
4093826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    }
4094826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    else
4095826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    {
4096826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      tmp_q.insert_entry(p1,p2,ident);
4097826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    }
4098826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  }
4099826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  //return all non GENERATE FDB to ftb queue
4100826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  while(tmp_q.m_size)
4101826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  {
4102826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    tmp_q.pop_entry(&p1,&p2,&ident);
4103826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    m_ftb_q.insert_entry(p1,p2,ident);
4104826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  }
4105826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  // pop all pending GENERATE EDB from etb queue
4106826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  while (m_etb_q.m_size)
4107826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  {
4108826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    m_etb_q.pop_entry(&p1,&p2,&ident);
4109826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    if(ident == OMX_COMPONENT_GENERATE_EBD)
4110826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    {
4111826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      pending_bd_q.insert_entry(p1,p2,ident);
4112826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    }
4113826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    else
4114826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    {
4115826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      tmp_q.insert_entry(p1,p2,ident);
4116826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    }
4117826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  }
4118826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  //return all non GENERATE FDB to etb queue
4119826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  while(tmp_q.m_size)
4120826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  {
4121826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    tmp_q.pop_entry(&p1,&p2,&ident);
4122826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    m_etb_q.insert_entry(p1,p2,ident);
4123826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  }
4124826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  pthread_mutex_unlock(&m_lock);
4125826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  // process all pending buffer dones
4126826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  while(pending_bd_q.m_size)
4127826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  {
4128826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    pending_bd_q.pop_entry(&p1,&p2,&ident);
4129826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    switch(ident)
4130826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    {
41317eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    case OMX_COMPONENT_GENERATE_EBD:
4132826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        if(empty_buffer_done(&m_cmp, (OMX_BUFFERHEADERTYPE *)p1) != OMX_ErrorNone)
4133826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        {
4134826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev          DEBUG_PRINT_ERROR("\nERROR: empty_buffer_done() failed!\n");
4135826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev          omx_report_error ();
4136826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        }
4137826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        break;
4138826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev
4139826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      case OMX_COMPONENT_GENERATE_FBD:
4140826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        if(fill_buffer_done(&m_cmp, (OMX_BUFFERHEADERTYPE *)p1) != OMX_ErrorNone )
4141826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        {
4142826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev          DEBUG_PRINT_ERROR("\nERROR: fill_buffer_done() failed!\n");
4143826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev          omx_report_error ();
4144826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        }
4145826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        break;
4146826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    }
4147826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  }
4148826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev}
4149826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev
4150826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#ifdef MAX_RES_720P
4151826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan MalchevOMX_ERRORTYPE omx_video::get_supported_profile_level(OMX_VIDEO_PARAM_PROFILELEVELTYPE *profileLevelType)
4152826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev{
4153826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  OMX_ERRORTYPE eRet = OMX_ErrorNone;
4154826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  if(!profileLevelType)
4155826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    return OMX_ErrorBadParameter;
4156826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev
4157826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  if(profileLevelType->nPortIndex == 1) {
4158826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    if (m_sOutPortDef.format.video.eCompressionFormat == OMX_VIDEO_CodingAVC)
4159826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    {
4160826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      if (profileLevelType->nProfileIndex == 0)
4161826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      {
4162826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        profileLevelType->eProfile = OMX_VIDEO_AVCProfileBaseline;
4163826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        profileLevelType->eLevel   = OMX_VIDEO_AVCLevel31;
4164826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      }
4165826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      else if (profileLevelType->nProfileIndex == 1)
4166826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      {
4167826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        profileLevelType->eProfile = OMX_VIDEO_AVCProfileMain;
4168826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        profileLevelType->eLevel   = OMX_VIDEO_AVCLevel31;
4169826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      }
4170826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      else if(profileLevelType->nProfileIndex == 2)
4171826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      {
4172826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        profileLevelType->eProfile = OMX_VIDEO_AVCProfileHigh;
4173826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        profileLevelType->eLevel   = OMX_VIDEO_AVCLevel31;
4174826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      }
4175826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      else
4176826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      {
4177826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported nProfileIndex ret NoMore %d\n",
4178826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev            profileLevelType->nProfileIndex);
4179826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        eRet = OMX_ErrorNoMore;
4180826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      }
4181826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    }
4182826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    else if (m_sOutPortDef.format.video.eCompressionFormat == OMX_VIDEO_CodingH263)
4183826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    {
4184826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      if (profileLevelType->nProfileIndex == 0)
4185826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      {
4186826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        profileLevelType->eProfile = OMX_VIDEO_H263ProfileBaseline;
4187826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        profileLevelType->eLevel   = OMX_VIDEO_H263Level70;
4188826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      }
4189826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      else
4190826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      {
4191826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        DEBUG_PRINT_ERROR("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported nProfileIndex ret NoMore %d\n", profileLevelType->nProfileIndex);
4192826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        eRet = OMX_ErrorNoMore;
4193826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      }
4194826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    }
4195826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    else if(m_sOutPortDef.format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4)
4196826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    {
4197826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      if (profileLevelType->nProfileIndex == 0)
4198826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      {
4199826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        profileLevelType->eProfile = OMX_VIDEO_MPEG4ProfileSimple;
4200826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        profileLevelType->eLevel   = OMX_VIDEO_MPEG4Level5;
4201826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      }
4202826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      else if(profileLevelType->nProfileIndex == 1)
4203826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      {
4204826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        profileLevelType->eProfile = OMX_VIDEO_MPEG4ProfileAdvancedSimple;
4205826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        profileLevelType->eLevel   = OMX_VIDEO_MPEG4Level5;
4206826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      }
4207826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      else
4208826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      {
4209826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        DEBUG_PRINT_ERROR("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported nProfileIndex ret NoMore %d\n", profileLevelType->nProfileIndex);
4210826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        eRet = OMX_ErrorNoMore;
4211826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      }
4212826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    }
4213826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  }
4214826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  else
4215826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  {
4216826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    DEBUG_PRINT_ERROR("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported should be queries on Input port only %d\n", profileLevelType->nPortIndex);
4217826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    eRet = OMX_ErrorBadPortIndex;
4218826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  }
4219826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  DEBUG_PRINT_ERROR("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported for Input port returned Profile:%d, Level:%d\n",
4220826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev                    profileLevelType->eProfile,profileLevelType->eLevel);
4221826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  return eRet;
4222826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev}
4223826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#endif
4224826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev
4225826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#ifdef MAX_RES_1080P
4226826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan MalchevOMX_ERRORTYPE omx_video::get_supported_profile_level(OMX_VIDEO_PARAM_PROFILELEVELTYPE *profileLevelType)
4227826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev{
4228826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  OMX_ERRORTYPE eRet = OMX_ErrorNone;
4229826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  if(!profileLevelType)
4230826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    return OMX_ErrorBadParameter;
4231826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev
4232826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  if(profileLevelType->nPortIndex == 1) {
4233826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    if (m_sOutPortDef.format.video.eCompressionFormat == OMX_VIDEO_CodingAVC)
4234826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    {
4235826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      if (profileLevelType->nProfileIndex == 0)
4236826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      {
4237826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        profileLevelType->eProfile = OMX_VIDEO_AVCProfileBaseline;
4238826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        profileLevelType->eLevel   = OMX_VIDEO_AVCLevel4;
4239826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev
4240826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      }
4241826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      else if (profileLevelType->nProfileIndex == 1)
4242826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      {
4243826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        profileLevelType->eProfile = OMX_VIDEO_AVCProfileMain;
4244826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        profileLevelType->eLevel   = OMX_VIDEO_AVCLevel4;
4245826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      }
4246826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      else if(profileLevelType->nProfileIndex == 2)
4247826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      {
4248826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        profileLevelType->eProfile = OMX_VIDEO_AVCProfileHigh;
4249826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        profileLevelType->eLevel   = OMX_VIDEO_AVCLevel4;
4250826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      }
4251826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      else
4252826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      {
4253826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported nProfileIndex ret NoMore %d\n",
4254826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev            profileLevelType->nProfileIndex);
4255826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        eRet = OMX_ErrorNoMore;
4256826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      }
4257826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    }
4258826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    else if (m_sOutPortDef.format.video.eCompressionFormat == OMX_VIDEO_CodingH263)
4259826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    {
4260826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      if (profileLevelType->nProfileIndex == 0)
4261826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      {
4262826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        profileLevelType->eProfile = OMX_VIDEO_H263ProfileBaseline;
4263826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        profileLevelType->eLevel   = OMX_VIDEO_H263Level70;
4264826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      }
4265826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      else
4266826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      {
4267826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        DEBUG_PRINT_ERROR("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported nProfileIndex ret NoMore %d\n", profileLevelType->nProfileIndex);
4268826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        eRet = OMX_ErrorNoMore;
4269826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      }
4270826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    }
4271826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    else if(m_sOutPortDef.format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4)
4272826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    {
4273826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      if (profileLevelType->nProfileIndex == 0)
4274826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      {
4275826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        profileLevelType->eProfile = OMX_VIDEO_MPEG4ProfileSimple;
4276826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        profileLevelType->eLevel   = OMX_VIDEO_MPEG4Level5;
4277826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      }
4278826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      else if(profileLevelType->nProfileIndex == 1)
4279826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      {
4280826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        profileLevelType->eProfile = OMX_VIDEO_MPEG4ProfileAdvancedSimple;
4281826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        profileLevelType->eLevel   = OMX_VIDEO_MPEG4Level5;
4282826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      }
4283826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      else
4284826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      {
4285826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        DEBUG_PRINT_ERROR("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported nProfileIndex ret NoMore %d\n", profileLevelType->nProfileIndex);
4286826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        eRet = OMX_ErrorNoMore;
4287826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev      }
4288826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    }
4289826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  }
4290826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  else
4291826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  {
4292826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    DEBUG_PRINT_ERROR("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported should be queries on Input port only %d\n", profileLevelType->nPortIndex);
4293826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    eRet = OMX_ErrorBadPortIndex;
4294826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  }
4295826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  DEBUG_PRINT_ERROR("get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported for Input port returned Profile:%d, Level:%d\n",
4296826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev                    profileLevelType->eProfile,profileLevelType->eLevel);
4297826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  return eRet;
4298826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev}
4299826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev
4300826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#ifdef USE_ION
4301826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchevint omx_video::alloc_map_ion_memory(int size,struct ion_allocation_data *alloc_data,
4302826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev                                    struct ion_fd_data *fd_data,int flag)
4303826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev{
43047783f07680c4e868295efbd0cf55a1622a106522Deva Ramasubramanian  struct venc_ion buf_ion_info;
43057783f07680c4e868295efbd0cf55a1622a106522Deva Ramasubramanian  int ion_device_fd =-1,rc=0,ion_dev_flags = 0;
43067783f07680c4e868295efbd0cf55a1622a106522Deva Ramasubramanian  if (size <=0 || !alloc_data || !fd_data) {
43077783f07680c4e868295efbd0cf55a1622a106522Deva Ramasubramanian    DEBUG_PRINT_ERROR("\nInvalid input to alloc_map_ion_memory");
43087783f07680c4e868295efbd0cf55a1622a106522Deva Ramasubramanian    return -EINVAL;
4309826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev	}
431063a6c9bcb0bb20a516059e74ec4113b541f5e919Iliyan Malchev    ion_dev_flags = O_RDONLY;
4311826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        ion_device_fd = open (MEM_DEVICE,ion_dev_flags);
4312826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        if(ion_device_fd < 0)
4313826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        {
4314826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev           DEBUG_PRINT_ERROR("\nERROR: ION Device open() Failed");
4315826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev           return ion_device_fd;
4316826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        }
4317826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        alloc_data->len = size;
4318826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        alloc_data->align = 4096;
431963a6c9bcb0bb20a516059e74ec4113b541f5e919Iliyan Malchev        alloc_data->flags = 0;
432063a6c9bcb0bb20a516059e74ec4113b541f5e919Iliyan Malchev        if(!secure_session && (flag & ION_FLAG_CACHED))
432163a6c9bcb0bb20a516059e74ec4113b541f5e919Iliyan Malchev        {
432263a6c9bcb0bb20a516059e74ec4113b541f5e919Iliyan Malchev          alloc_data->flags = ION_FLAG_CACHED;
432363a6c9bcb0bb20a516059e74ec4113b541f5e919Iliyan Malchev        }
43247783f07680c4e868295efbd0cf55a1622a106522Deva Ramasubramanian
43257783f07680c4e868295efbd0cf55a1622a106522Deva Ramasubramanian        if (secure_session)
432663a6c9bcb0bb20a516059e74ec4113b541f5e919Iliyan Malchev           alloc_data->heap_mask = (ION_HEAP(MEM_HEAP_ID) | ION_SECURE);
43277783f07680c4e868295efbd0cf55a1622a106522Deva Ramasubramanian        else
432863a6c9bcb0bb20a516059e74ec4113b541f5e919Iliyan Malchev           alloc_data->heap_mask = (ION_HEAP(MEM_HEAP_ID) |
43297783f07680c4e868295efbd0cf55a1622a106522Deva Ramasubramanian                ION_HEAP(ION_IOMMU_HEAP_ID));
43307783f07680c4e868295efbd0cf55a1622a106522Deva Ramasubramanian
4331826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        rc = ioctl(ion_device_fd,ION_IOC_ALLOC,alloc_data);
4332826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        if(rc || !alloc_data->handle) {
4333826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev           DEBUG_PRINT_ERROR("\n ION ALLOC memory failed ");
4334826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev           alloc_data->handle =NULL;
4335826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev           close(ion_device_fd);
4336826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev           ion_device_fd = -1;
4337826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev           return ion_device_fd;
4338826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        }
4339826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        fd_data->handle = alloc_data->handle;
4340826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        rc = ioctl(ion_device_fd,ION_IOC_MAP,fd_data);
4341826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        if(rc) {
4342826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev            DEBUG_PRINT_ERROR("\n ION MAP failed ");
4343826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev            buf_ion_info.ion_alloc_data = *alloc_data;
4344826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev            buf_ion_info.ion_device_fd = ion_device_fd;
4345826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev            buf_ion_info.fd_ion_data = *fd_data;
4346826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev            free_ion_memory(&buf_ion_info);
4347826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev            fd_data->fd =-1;
4348826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev            ion_device_fd =-1;
4349826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        }
4350826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        return ion_device_fd;
4351826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev}
4352826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev
4353826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchevvoid omx_video::free_ion_memory(struct venc_ion *buf_ion_info)
4354826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev{
4355826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev     if (!buf_ion_info) {
4356826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        DEBUG_PRINT_ERROR("\n Invalid input to free_ion_memory");
43577783f07680c4e868295efbd0cf55a1622a106522Deva Ramasubramanian        return;
4358826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev     }
4359826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev     if (ioctl(buf_ion_info->ion_device_fd,ION_IOC_FREE,
4360826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev              &buf_ion_info->ion_alloc_data.handle)) {
4361826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev         DEBUG_PRINT_ERROR("\n ION free failed ");
4362826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev         return;
4363826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev     }
4364826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev     close(buf_ion_info->ion_device_fd);
4365826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev     buf_ion_info->ion_alloc_data.handle = NULL;
4366826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev     buf_ion_info->ion_device_fd = -1;
4367826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev     buf_ion_info->fd_ion_data.fd = -1;
4368826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev}
4369826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#endif
4370826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#endif
4371826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev#ifdef _ANDROID_ICS_
4372826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchevvoid omx_video::omx_release_meta_buffer(OMX_BUFFERHEADERTYPE *buffer)
4373826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev{
4374826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  if(buffer && meta_mode_enable)
4375826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev  {
4376826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    encoder_media_buffer_type *media_ptr;
4377826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    struct pmem Input_pmem;
43787eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    unsigned int index_pmem = 0;
4379826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    bool meta_error = false;
43807eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George
43817eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    index_pmem = (buffer - m_inp_mem_ptr);
43827eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    if(mUseProxyColorFormat &&
43837eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George       (index_pmem < m_sInPortDef.nBufferCountActual)) {
43847eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George        if(!dev_free_buf((&m_pInput_pmem[index_pmem]),PORT_INDEX_IN)){
43857eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George          DEBUG_PRINT_ERROR("\n omx_release_meta_buffer dev free failed");
43867eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George        }
43877eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    } else {
43887eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      media_ptr = (encoder_media_buffer_type *) buffer->pBuffer;
43897eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      if(media_ptr && media_ptr->meta_handle)
43907eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      {
43917eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George        if(media_ptr->buffer_type == kMetadataBufferTypeCameraSource &&
43927eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George           media_ptr->meta_handle->numFds == 1 &&
43937eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George           media_ptr->meta_handle->numInts == 2) {
43947eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George          Input_pmem.fd = media_ptr->meta_handle->data[0];
43957eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George          Input_pmem.buffer = media_ptr;
43967eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George          Input_pmem.size = media_ptr->meta_handle->data[2];
43977eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George          Input_pmem.offset = media_ptr->meta_handle->data[1];
43987eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George          DEBUG_PRINT_LOW("EBD fd = %d, offset = %d, size = %d",Input_pmem.fd,
43997eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George                            Input_pmem.offset,
44007eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George                            Input_pmem.size);
44017eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George        } else if(media_ptr->buffer_type == kMetadataBufferTypeGrallocSource) {
44027eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George          private_handle_t *handle = (private_handle_t *)media_ptr->meta_handle;
44037eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George          Input_pmem.buffer = media_ptr;
44047eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George          Input_pmem.fd = handle->fd;
44057eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George          Input_pmem.offset = 0;
44067eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George          Input_pmem.size = handle->size;
44077eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George        } else {
44087eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George          meta_error = true;
44097eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George          DEBUG_PRINT_ERROR(" Meta Error set in EBD");
44107eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George        }
44117eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George        if(!meta_error)
44127eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George           meta_error = !dev_free_buf(&Input_pmem,PORT_INDEX_IN);
44137eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George          if(meta_error)
44147eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George          {
44157eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George           DEBUG_PRINT_ERROR(" Warning dev_free_buf failed flush value is %d",
44167eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George               input_flush_progress);
44177eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George          }
44187eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George        }
44197eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George     }
44207eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  }
44217eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George}
44227eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George#endif
44237eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew Georgeomx_video::omx_c2d_conv::omx_c2d_conv()
44247eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George{
44257eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  c2dcc = NULL;
44267eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  mLibHandle = NULL;
44277eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  mConvertOpen = NULL;
44287eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  mConvertClose = NULL;
44297eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  src_format = NV12_2K;
44307eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George}
44317eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George
44327eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew Georgebool omx_video::omx_c2d_conv::init() {
44337eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  bool status = true;
44347eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  if(mLibHandle || mConvertOpen || mConvertClose) {
44357eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    DEBUG_PRINT_ERROR("\n omx_c2d_conv::init called twice");
44367eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    status = false;
44377eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  }
44387eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  if(status) {
44397eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    mLibHandle = dlopen("libc2dcolorconvert.so", RTLD_LAZY);
44407eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    if(mLibHandle){
44417eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George       mConvertOpen = (createC2DColorConverter_t *)
44427eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George       dlsym(mLibHandle,"createC2DColorConverter");
44437eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George       mConvertClose = (destroyC2DColorConverter_t *)
44447eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George       dlsym(mLibHandle,"destroyC2DColorConverter");
44457eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George       if(!mConvertOpen || !mConvertClose)
44467eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George         status = false;
44477eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    } else
44487eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      status = false;
44497eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  }
44507eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  if(!status && mLibHandle){
44517eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    dlclose(mLibHandle);
44527eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    mLibHandle = NULL;
44537eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    mConvertOpen = NULL;
44547eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    mConvertClose = NULL;
44557eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  }
44567eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  return status;
44577eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George}
44587eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George
4459e0403d8b56d9b2def405981159cddacbdd461ed3Praveen Chavanbool omx_video::omx_c2d_conv::convert(int src_fd, void *src_base, void *src_viraddr,
4460e0403d8b56d9b2def405981159cddacbdd461ed3Praveen Chavan     int dest_fd, void *dest_base, void *dest_viraddr)
44617eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George{
44627eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  int result;
44637eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  if(!src_viraddr || !dest_viraddr || !c2dcc){
44647eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    DEBUG_PRINT_ERROR("\n Invalid arguments omx_c2d_conv::convert");
44657eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    return false;
44667eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  }
4467e0403d8b56d9b2def405981159cddacbdd461ed3Praveen Chavan  result =  c2dcc->convertC2D(src_fd, src_base, src_viraddr,
4468e0403d8b56d9b2def405981159cddacbdd461ed3Praveen Chavan                              dest_fd, dest_base, dest_viraddr);
44697eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  DEBUG_PRINT_LOW("\n Color convert status %d",result);
44707eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  return ((result < 0)?false:true);
44717eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George}
44727eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George
44737eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew Georgebool omx_video::omx_c2d_conv::open(unsigned int height,unsigned int width,
44747eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George     ColorConvertFormat src, ColorConvertFormat dest)
44757eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George{
44767eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  bool status = false;
4477e0403d8b56d9b2def405981159cddacbdd461ed3Praveen Chavan  size_t srcStride = 0;
44787eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  if(!c2dcc) {
44797eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George     c2dcc = mConvertOpen(width, height, width, height,
4480e0403d8b56d9b2def405981159cddacbdd461ed3Praveen Chavan             src, dest, 0, srcStride);
44817eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George     if(c2dcc) {
44827eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George       src_format = src;
44837eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George       status = true;
44847eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George     } else
44857eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George       DEBUG_PRINT_ERROR("\n mConvertOpen failed");
44867eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  }
44877eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George   return status;
44887eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George}
44897eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew Georgevoid omx_video::omx_c2d_conv::close()
44907eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George{
44917eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  if(mLibHandle) {
44927eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    if(mConvertClose && c2dcc)
44937eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George     mConvertClose(c2dcc);
44947eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    c2dcc = NULL;
44957eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  }
44967eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George}
44977eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew Georgeomx_video::omx_c2d_conv::~omx_c2d_conv()
44987eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George{
44997eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  DEBUG_PRINT_ERROR("\n Destroy C2D instance");
45007eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  if(mLibHandle) {
45017eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    if(mConvertClose && c2dcc)
45027eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      mConvertClose(c2dcc);
45037eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    dlclose(mLibHandle);
45047eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  }
45057eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  c2dcc = NULL;
45067eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  mLibHandle = NULL;
45077eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  mConvertOpen = NULL;
45087eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  mConvertClose = NULL;
45097eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George}
45107eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew Georgeint omx_video::omx_c2d_conv::get_src_format()
45117eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George{
45127eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  int format = -1;
45137eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  if(src_format == NV12_2K) {
45147eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    format = HAL_PIXEL_FORMAT_NV12_ENCODEABLE;
45157eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  } else if(src_format == RGBA8888) {
45167eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    format = HAL_PIXEL_FORMAT_RGBA_8888;
45177eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  }
45187eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  return format;
45197eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George}
45207eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew Georgebool omx_video::omx_c2d_conv::get_buffer_size(int port,unsigned int &buf_size)
45217eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George{
45227eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  int cret = 0;
45237eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  bool ret = false;
45247eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  C2DBuffReq bufferreq;
45257eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  if(c2dcc){
45267eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    bufferreq.size = 0;
45277eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    cret = c2dcc->getBuffReq(port,&bufferreq);
45287eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    DEBUG_PRINT_LOW("\n Status of getbuffer is %d", cret);
45297eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    ret = (cret)?false:true;
45307eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    buf_size = bufferreq.size;
45317eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  }
45327eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  return ret;
45337eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George}
45347eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew GeorgeOMX_ERRORTYPE  omx_video::empty_this_buffer_opaque(OMX_IN OMX_HANDLETYPE hComp,
45357eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George                                                  OMX_IN OMX_BUFFERHEADERTYPE* buffer)
45367eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George{
45377eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  unsigned nBufIndex = 0;
45387eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  OMX_ERRORTYPE ret = OMX_ErrorNone;
45397eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  encoder_media_buffer_type *media_buffer;
45407eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  DEBUG_PRINT_LOW("\n ETBProxyOpaque: buffer[%p]\n", buffer);
45417eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George
45427eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  if(buffer == NULL) {
45437eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    DEBUG_PRINT_ERROR("\nERROR: ETBProxyA: Invalid buffer[%p]\n",buffer);
45447eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    return OMX_ErrorBadParameter;
45457eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  }
45467eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  nBufIndex = buffer - meta_buffer_hdr;
45477eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  if(nBufIndex >= m_sInPortDef.nBufferCountActual) {
45487eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    DEBUG_PRINT_ERROR("\nERROR: ETBProxyA: Invalid bufindex = %u\n",
45497eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George                      nBufIndex);
45507eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    return OMX_ErrorBadParameter;
45517eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  }
45527eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  media_buffer = (encoder_media_buffer_type *)buffer->pBuffer;
45537eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  private_handle_t *handle = (private_handle_t *)media_buffer->meta_handle;
45547eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  /*Enable following code once private handle color format is
45557eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    updated correctly*/
45567eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George
4557be03db07985878ca3da2edf5341261c6b67accd7Praveen Chavan  if(buffer->nFilledLen > 0) {
4558be03db07985878ca3da2edf5341261c6b67accd7Praveen Chavan    if(c2d_opened && handle->format != c2d_conv.get_src_format()) {
4559be03db07985878ca3da2edf5341261c6b67accd7Praveen Chavan      c2d_conv.close();
4560be03db07985878ca3da2edf5341261c6b67accd7Praveen Chavan      c2d_opened = false;
4561be03db07985878ca3da2edf5341261c6b67accd7Praveen Chavan    }
4562be03db07985878ca3da2edf5341261c6b67accd7Praveen Chavan    if (!c2d_opened) {
4563be03db07985878ca3da2edf5341261c6b67accd7Praveen Chavan        if (handle->format == HAL_PIXEL_FORMAT_RGBA_8888) {
4564be03db07985878ca3da2edf5341261c6b67accd7Praveen Chavan          DEBUG_PRINT_ERROR("\n open Color conv for RGBA888");
4565be03db07985878ca3da2edf5341261c6b67accd7Praveen Chavan          if(!c2d_conv.open(m_sInPortDef.format.video.nFrameHeight,
4566be03db07985878ca3da2edf5341261c6b67accd7Praveen Chavan               m_sInPortDef.format.video.nFrameWidth,RGBA8888,NV12_2K)){
4567be03db07985878ca3da2edf5341261c6b67accd7Praveen Chavan             m_pCallbacks.EmptyBufferDone(hComp,m_app_data,buffer);
4568be03db07985878ca3da2edf5341261c6b67accd7Praveen Chavan             DEBUG_PRINT_ERROR("\n Color conv open failed");
4569be03db07985878ca3da2edf5341261c6b67accd7Praveen Chavan             return OMX_ErrorBadParameter;
4570be03db07985878ca3da2edf5341261c6b67accd7Praveen Chavan          }
4571be03db07985878ca3da2edf5341261c6b67accd7Praveen Chavan          c2d_opened = true;
4572be03db07985878ca3da2edf5341261c6b67accd7Praveen Chavan        } else if(handle->format != HAL_PIXEL_FORMAT_NV12_ENCODEABLE) {
4573be03db07985878ca3da2edf5341261c6b67accd7Praveen Chavan          DEBUG_PRINT_ERROR("\n Incorrect color format");
4574be03db07985878ca3da2edf5341261c6b67accd7Praveen Chavan          m_pCallbacks.EmptyBufferDone(hComp,m_app_data,buffer);
4575be03db07985878ca3da2edf5341261c6b67accd7Praveen Chavan          return OMX_ErrorBadParameter;
4576826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev        }
4577be03db07985878ca3da2edf5341261c6b67accd7Praveen Chavan    }
45787eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  }
45797eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George
45807eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  if(input_flush_progress == true)
45817eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  {
45827eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    m_pCallbacks.EmptyBufferDone(hComp,m_app_data,buffer);
45837eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    DEBUG_PRINT_ERROR("\nERROR: ETBProxyA: Input flush in progress");
45847eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    return OMX_ErrorNone;
45857eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  }
45867eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George
45877eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  if(!psource_frame) {
45887eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    psource_frame = buffer;
45897eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    ret = push_input_buffer(hComp);
45907eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  } else {
45917eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    if (!m_opq_meta_q.insert_entry((unsigned)buffer,0,0)) {
45927eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      DEBUG_PRINT_ERROR("\nERROR: ETBProxy: Queue is full");
45937eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      ret = OMX_ErrorBadParameter;
4594826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev    }
45957eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  }
45967eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  if(ret != OMX_ErrorNone) {
45977eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    m_pCallbacks.EmptyBufferDone(hComp,m_app_data,buffer);
45987eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    DEBUG_PRINT_LOW("\nERROR: ETBOpaque failed:");
45997eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  }
46007eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  return ret;
46017eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George}
46027eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew GeorgeOMX_ERRORTYPE omx_video::queue_meta_buffer(OMX_HANDLETYPE hComp,
46037eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George     struct pmem &Input_pmem_info) {
46047eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George
46057eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  OMX_ERRORTYPE ret = OMX_ErrorNone;
46067eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  unsigned address = 0,p2,id;
46077eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George
46087eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  DEBUG_PRINT_LOW("\n In queue Meta Buffer");
46097eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  if(!psource_frame || !pdest_frame) {
46107eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    DEBUG_PRINT_ERROR("\n convert_queue_buffer invalid params");
46117eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    return OMX_ErrorBadParameter;
46127eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  }
46137eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George
4614be03db07985878ca3da2edf5341261c6b67accd7Praveen Chavan  if(psource_frame->nFilledLen > 0) {
4615be03db07985878ca3da2edf5341261c6b67accd7Praveen Chavan   if(dev_use_buf(&Input_pmem_info,PORT_INDEX_IN,0) != true) {
4616be03db07985878ca3da2edf5341261c6b67accd7Praveen Chavan     DEBUG_PRINT_ERROR("\nERROR: in dev_use_buf");
4617be03db07985878ca3da2edf5341261c6b67accd7Praveen Chavan     post_event ((unsigned int)psource_frame,0,OMX_COMPONENT_GENERATE_EBD);
4618be03db07985878ca3da2edf5341261c6b67accd7Praveen Chavan     ret = OMX_ErrorBadParameter;
4619be03db07985878ca3da2edf5341261c6b67accd7Praveen Chavan   }
46207eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  }
46217eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George
46227eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  if(ret == OMX_ErrorNone)
46237eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    ret = empty_this_buffer_proxy(hComp,psource_frame);
46247eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George
46257eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  if(ret == OMX_ErrorNone) {
46267eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    psource_frame = NULL;
46277eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    if(!psource_frame && m_opq_meta_q.m_size) {
46287eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      m_opq_meta_q.pop_entry(&address,&p2,&id);
46297eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      psource_frame = (OMX_BUFFERHEADERTYPE* ) address;
46307eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    }
46317eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  }
46327eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  return ret;
46337eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George}
46347eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George
46357eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew GeorgeOMX_ERRORTYPE omx_video::convert_queue_buffer(OMX_HANDLETYPE hComp,
46367eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George     struct pmem &Input_pmem_info,unsigned &index){
46377eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George
46387eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  unsigned char *uva;
46397eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  OMX_ERRORTYPE ret = OMX_ErrorNone;
46407eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  unsigned address = 0,p2,id;
46417eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George
46427eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  DEBUG_PRINT_LOW("\n In Convert and queue Meta Buffer");
46437eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  if(!psource_frame || !pdest_frame) {
46447eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    DEBUG_PRINT_ERROR("\n convert_queue_buffer invalid params");
46457eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    return OMX_ErrorBadParameter;
46467eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  }
46477eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George
46487eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  if(!psource_frame->nFilledLen){
4649be03db07985878ca3da2edf5341261c6b67accd7Praveen Chavan    if(psource_frame->nFlags & OMX_BUFFERFLAG_EOS){
4650be03db07985878ca3da2edf5341261c6b67accd7Praveen Chavan        pdest_frame->nFilledLen = psource_frame->nFilledLen;
4651be03db07985878ca3da2edf5341261c6b67accd7Praveen Chavan        pdest_frame->nTimeStamp = psource_frame->nTimeStamp;
4652be03db07985878ca3da2edf5341261c6b67accd7Praveen Chavan        pdest_frame->nFlags = psource_frame->nFlags;
4653be03db07985878ca3da2edf5341261c6b67accd7Praveen Chavan        DEBUG_PRINT_HIGH("\n Skipping color conversion for empty EOS \
4654be03db07985878ca3da2edf5341261c6b67accd7Praveen Chavan          Buffer header=%p filled-len=%d", pdest_frame,pdest_frame->nFilledLen);
4655be03db07985878ca3da2edf5341261c6b67accd7Praveen Chavan    } else {
4656be03db07985878ca3da2edf5341261c6b67accd7Praveen Chavan        pdest_frame->nOffset = 0;
4657be03db07985878ca3da2edf5341261c6b67accd7Praveen Chavan        pdest_frame->nFilledLen = 0;
4658be03db07985878ca3da2edf5341261c6b67accd7Praveen Chavan        pdest_frame->nTimeStamp = psource_frame->nTimeStamp;
4659be03db07985878ca3da2edf5341261c6b67accd7Praveen Chavan        pdest_frame->nFlags = psource_frame->nFlags;
4660be03db07985878ca3da2edf5341261c6b67accd7Praveen Chavan        DEBUG_PRINT_LOW("\n Buffer header %p Filled len size %d",
4661be03db07985878ca3da2edf5341261c6b67accd7Praveen Chavan           pdest_frame,pdest_frame->nFilledLen);
4662be03db07985878ca3da2edf5341261c6b67accd7Praveen Chavan    }
46637eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  } else {
46647eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George     uva = (unsigned char *)mmap(NULL, Input_pmem_info.size,
46657eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George                           PROT_READ|PROT_WRITE,
46667eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George                           MAP_SHARED,Input_pmem_info.fd,0);
46677eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George     if(uva == MAP_FAILED) {
46687eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George       ret = OMX_ErrorBadParameter;
46697eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George     } else {
4670e0403d8b56d9b2def405981159cddacbdd461ed3Praveen Chavan       if(!c2d_conv.convert(Input_pmem_info.fd, uva, uva,
4671e0403d8b56d9b2def405981159cddacbdd461ed3Praveen Chavan          m_pInput_pmem[index].fd, pdest_frame->pBuffer, pdest_frame->pBuffer)) {
46727eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George          DEBUG_PRINT_ERROR("\n Color Conversion failed");
46737eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George          ret = OMX_ErrorBadParameter;
46747eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George       } else {
46757eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George          unsigned int buf_size = 0;
46767eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George          if (!c2d_conv.get_buffer_size(C2D_OUTPUT,buf_size))
46777eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George            ret = OMX_ErrorBadParameter;
46787eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George          else {
46797eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George            pdest_frame->nOffset = 0;
468045b5b3b17dc1ac1a1a68112e200af6887144b660Haynes Mathew George            if(!buf_size || buf_size > pdest_frame->nAllocLen) {
468145b5b3b17dc1ac1a1a68112e200af6887144b660Haynes Mathew George              DEBUG_PRINT_ERROR("\n convert_queue_buffer buffer"
468245b5b3b17dc1ac1a1a68112e200af6887144b660Haynes Mathew George               "size mismatch buf size %d alloc size %d",
468345b5b3b17dc1ac1a1a68112e200af6887144b660Haynes Mathew George                      buf_size, pdest_frame->nAllocLen);
468445b5b3b17dc1ac1a1a68112e200af6887144b660Haynes Mathew George              ret = OMX_ErrorBadParameter;
468545b5b3b17dc1ac1a1a68112e200af6887144b660Haynes Mathew George              buf_size = 0;
468645b5b3b17dc1ac1a1a68112e200af6887144b660Haynes Mathew George            }
46877eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George            pdest_frame->nFilledLen = buf_size;
46887eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George            pdest_frame->nTimeStamp = psource_frame->nTimeStamp;
46897eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George            pdest_frame->nFlags = psource_frame->nFlags;
46907eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George            DEBUG_PRINT_LOW("\n Buffer header %p Filled len size %d",
46917eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George               pdest_frame,pdest_frame->nFilledLen);
46927eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George           }
46937eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George         }
46947eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George         munmap(uva,Input_pmem_info.size);
46957eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      }
46967eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    }
469745b5b3b17dc1ac1a1a68112e200af6887144b660Haynes Mathew George    if((ret == OMX_ErrorNone) &&
469845b5b3b17dc1ac1a1a68112e200af6887144b660Haynes Mathew George       dev_use_buf(&m_pInput_pmem[index],PORT_INDEX_IN,0) != true) {
46997eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      DEBUG_PRINT_ERROR("\nERROR: in dev_use_buf");
47007eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      post_event ((unsigned int)pdest_frame,0,OMX_COMPONENT_GENERATE_EBD);
47017eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      ret = OMX_ErrorBadParameter;
47027eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    }
47037eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    if(ret == OMX_ErrorNone)
47047eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      ret = empty_this_buffer_proxy(hComp,pdest_frame);
47057eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    if(ret == OMX_ErrorNone) {
47067eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      m_pCallbacks.EmptyBufferDone(hComp ,m_app_data, psource_frame);
47077eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      psource_frame = NULL;
47087eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      pdest_frame = NULL;
47097eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      if(!psource_frame && m_opq_meta_q.m_size) {
47107eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George        m_opq_meta_q.pop_entry(&address,&p2,&id);
47117eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George        psource_frame = (OMX_BUFFERHEADERTYPE* ) address;
47127eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      }
47137eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      if(!pdest_frame && m_opq_pmem_q.m_size) {
47147eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George        m_opq_pmem_q.pop_entry(&address,&p2,&id);
47157eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George        pdest_frame = (OMX_BUFFERHEADERTYPE* ) address;
47167eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George        DEBUG_PRINT_LOW("\n pdest_frame pop address is %p",pdest_frame);
47177eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      }
47187eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    }
47197eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    return ret;
47207eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George}
47217eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George
47227eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew GeorgeOMX_ERRORTYPE omx_video::push_input_buffer(OMX_HANDLETYPE hComp)
47237eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George{
47247eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  unsigned address = 0,p2,id, index = 0;
47257eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  OMX_ERRORTYPE ret = OMX_ErrorNone;
47267eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George
47277eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  if(!psource_frame && m_opq_meta_q.m_size) {
47287eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    m_opq_meta_q.pop_entry(&address,&p2,&id);
47297eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    psource_frame = (OMX_BUFFERHEADERTYPE* ) address;
47307eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  }
47317eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  if(!pdest_frame && m_opq_pmem_q.m_size) {
47327eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    m_opq_pmem_q.pop_entry(&address,&p2,&id);
47337eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    pdest_frame = (OMX_BUFFERHEADERTYPE* ) address;
47347eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  }
47357eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  while(psource_frame != NULL && pdest_frame != NULL &&
47367eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George        ret == OMX_ErrorNone) {
47377eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    struct pmem Input_pmem_info;
47387eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    encoder_media_buffer_type *media_buffer;
47397eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    index = pdest_frame - m_inp_mem_ptr;
47407eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    if(index >= m_sInPortDef.nBufferCountActual){
47417eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George       DEBUG_PRINT_ERROR("\n Output buffer index is wrong %d act count %d",
47427eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George                         index,m_sInPortDef.nBufferCountActual);
47437eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George       return OMX_ErrorBadParameter;
47447eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    }
47457eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    media_buffer = (encoder_media_buffer_type *)psource_frame->pBuffer;
47467eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    /*Will enable to verify camcorder in current TIPS can be removed*/
47477eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    if(media_buffer->buffer_type == kMetadataBufferTypeCameraSource) {
47487eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      Input_pmem_info.buffer = media_buffer;
47497eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      Input_pmem_info.fd = media_buffer->meta_handle->data[0];
47507eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      Input_pmem_info.offset = media_buffer->meta_handle->data[1];
47517eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      Input_pmem_info.size = media_buffer->meta_handle->data[2];
47527eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      DEBUG_PRINT_LOW("ETB fd = %d, offset = %d, size = %d",Input_pmem_info.fd,
47537eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George                        Input_pmem_info.offset,
47547eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George                        Input_pmem_info.size);
47557eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      ret = queue_meta_buffer(hComp,Input_pmem_info);
4756be03db07985878ca3da2edf5341261c6b67accd7Praveen Chavan    } else if(psource_frame->nFlags & OMX_BUFFERFLAG_EOS & mUseProxyColorFormat) {
4757be03db07985878ca3da2edf5341261c6b67accd7Praveen Chavan       ret = convert_queue_buffer(hComp,Input_pmem_info,index);
47587eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    } else {
47597eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      private_handle_t *handle = (private_handle_t *)media_buffer->meta_handle;
47607eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      Input_pmem_info.buffer = media_buffer;
47617eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      Input_pmem_info.fd = handle->fd;
47627eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      Input_pmem_info.offset = 0;
47637eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      Input_pmem_info.size = handle->size;
47647eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      if(handle->format == HAL_PIXEL_FORMAT_RGBA_8888)
47657eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George        ret = convert_queue_buffer(hComp,Input_pmem_info,index);
47667eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      else if(handle->format == HAL_PIXEL_FORMAT_NV12_ENCODEABLE)
47677eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George        ret = queue_meta_buffer(hComp,Input_pmem_info);
47687eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George      else
47697eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George        ret = OMX_ErrorBadParameter;
47707eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George    }
47717eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George   }
47727eecc360a0b15aec6389c96ec23980231af4ddc6Haynes Mathew George  return ret;
4773826ececcbea342f7a0b92ec61847f1c95d384e05Iliyan Malchev}
4774