portbase.h revision 7b94bb78335b52b812d8b4137ce80799bb6b9125
1/*
2 * Copyright (C) 2009 Wind River Systems.
3 */
4
5#ifndef __PORTBASE_H
6#define __PORTBASE_H
7
8#include <pthread.h>
9
10#include <OMX_Core.h>
11#include <OMX_Component.h>
12
13#include <list.h>
14
15class PortBase
16{
17public:
18    /*
19     * constructor & destructor
20     */
21    PortBase();
22    PortBase(const OMX_PARAM_PORTDEFINITIONTYPE *param);
23    virtual ~PortBase();
24
25    /* end of constructor & destructor */
26
27    /*
28     * accessor
29     */
30    /* owner */
31    void SetOwner(OMX_COMPONENTTYPE *handle);
32    OMX_COMPONENTTYPE *GetOwner(void);
33
34    /*
35     * component methods & helpers
36     */
37    /* Get/SetParameter */
38    void SetPortParam(
39        const OMX_PARAM_PORTDEFINITIONTYPE *pComponentParameterStructure);
40    const OMX_PARAM_PORTDEFINITIONTYPE *GetPortParam(void);
41    /* audio parameter */
42    void SetAudioPortParam(
43        const OMX_AUDIO_PARAM_PORTFORMATTYPE *pComponentParameterStructure);
44    const OMX_AUDIO_PARAM_PORTFORMATTYPE *GetAudioPortParam(void);
45
46    /* Use/Allocate/FreeBuffer */
47    OMX_ERRORTYPE UseBuffer(OMX_BUFFERHEADERTYPE **ppBufferHdr,
48                            OMX_U32 nPortIndex,
49                            OMX_PTR pAppPrivate,
50                            OMX_U32 nSizeBytes,
51                            OMX_U8 *pBuffer);
52    OMX_ERRORTYPE AllocateBuffer(OMX_BUFFERHEADERTYPE **ppBuffer,
53                                 OMX_U32 nPortIndex,
54                                 OMX_PTR pAppPrivate,
55                                 OMX_U32 nSizeBytes);
56    OMX_ERRORTYPE FreeBuffer(OMX_U32 nPortIndex,
57                             OMX_BUFFERHEADERTYPE *pBuffer);
58
59    /*
60     * called in ComponentBase::TransStateToLoaded(OMX_StateIdle) or
61     * in ComponentBase::TransStateToIdle(OMX_StateLoaded)
62     * wokeup by Use/Allocate/FreeBuffer
63     */
64    void WaitPortBufferCompletion(void);
65
66    /* end of component methods & helpers */
67
68private:
69    /* common routines for constructor */
70    void __PortBase(void);
71
72    /* buffer headers */
73    struct list *buffer_hdrs;
74    OMX_U32 nr_buffer_hdrs;
75    bool buffer_hdrs_completion; /* Use/Allocate/FreeBuffer completion flag */
76    pthread_mutex_t hdrs_lock;
77    pthread_cond_t hdrs_wait;
78
79    /* parameter */
80    OMX_PARAM_PORTDEFINITIONTYPE portparam;
81    OMX_AUDIO_PARAM_PORTFORMATTYPE audioparam;
82
83    /* owner handle */
84    OMX_COMPONENTTYPE *owner;
85};
86
87#endif /* __PORTBASE_H */
88