summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/omx/tests/OMXHarness.h
blob: bb8fd0c93f85e8056dbb2d364444ec486ffed482 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
 * Copyright (C) 2009 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef OMX_HARNESS_H_

#define OMX_HARNESS_H_

#include <media/IOMX.h>
#include <utils/List.h>
#include <utils/Vector.h>
#include <utils/threads.h>

#include <OMX_Component.h>

namespace android {

class MemoryDealer;

struct Harness : public BnOMXObserver {
    enum BufferFlags {
        kBufferBusy = 1
    };
    struct Buffer {
        IOMX::buffer_id mID;
        sp<IMemory> mMemory;
        uint32_t mFlags;
    };

    Harness();

    status_t initCheck() const;

    status_t dequeueMessageForNode(
            IOMX::node_id node, omx_message *msg, int64_t timeoutUs = -1);

    status_t dequeueMessageForNodeIgnoringBuffers(
            IOMX::node_id node,
            Vector<Buffer> *inputBuffers,
            Vector<Buffer> *outputBuffers,
            omx_message *msg, int64_t timeoutUs = -1);

    status_t getPortDefinition(
            IOMX::node_id node, OMX_U32 portIndex,
            OMX_PARAM_PORTDEFINITIONTYPE *def);

    status_t allocatePortBuffers(
            const sp<MemoryDealer> &dealer,
            IOMX::node_id node, OMX_U32 portIndex,
            Vector<Buffer> *buffers);

    status_t setRole(IOMX::node_id node, const char *role);

    status_t testStateTransitions(
            const char *componentName, const char *componentRole);

    status_t testSeek(
            const char *componentName, const char *componentRole);

    status_t test(
            const char *componentName, const char *componentRole);

    status_t testAll();

    virtual void onMessage(const omx_message &msg);

protected:
    virtual ~Harness();

private:
    friend struct NodeReaper;

    Mutex mLock;

    status_t mInitCheck;
    sp<IOMX> mOMX;
    List<omx_message> mMessageQueue;
    Condition mMessageAddedCondition;

    status_t initOMX();

    bool handleBufferMessage(
            const omx_message &msg,
            Vector<Buffer> *inputBuffers,
            Vector<Buffer> *outputBuffers);

    Harness(const Harness &);
    Harness &operator=(const Harness &);
};

}  // namespace android

#endif  // OMX_HARNESS_H_