File: v4l2_decode.h

package info (click to toggle)
libyami 1.3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 4,152 kB
  • sloc: cpp: 44,247; ansic: 1,255; makefile: 728; lisp: 479; sh: 21; python: 19
file content (128 lines) | stat: -rw-r--r-- 4,023 bytes parent folder | download | duplicates (3)
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
 * Copyright (C) 2014 Intel Corporation. All rights reserved.
 *
 * 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 v4l2_decode_h
#define v4l2_decode_h

#include <vector>

#include "v4l2_codecbase.h"
#include "VideoDecoderInterface.h"
#include "common/Thread.h"
#include "common/Functional.h"
#include <BufferPipe.h>

using namespace YamiMediaCodec;
typedef SharedPtr < IVideoDecoder > DecoderPtr;
typedef std::function<int32_t(void)> Task;
class V4l2Decoder : public V4l2CodecBase
{
public:
    V4l2Decoder();
     ~V4l2Decoder();

    virtual int32_t ioctl(int request, void* arg);
    virtual void* mmap(void* addr, size_t length,
                         int prot, int flags, unsigned int offset);
#ifdef __ENABLE_EGL__
    virtual int32_t useEglImage(EGLDisplay eglDisplay, EGLContext eglContext, uint32_t buffer_index, void* egl_image);
#endif
    virtual int32_t setFrameMemoryType(VideoDataMemoryType memory_type);

    class Output;
    friend class EglOutput;
    friend class ExternalBufferOutput;
    friend class ExternalDmaBufOutput;

protected:
    virtual bool start();
    virtual bool stop();
    virtual bool acceptInputBuffer(struct v4l2_buffer *qbuf);
    virtual bool giveOutputBuffer(struct v4l2_buffer *dqbuf);
    virtual bool inputPulse(uint32_t index);
    virtual bool outputPulse(uint32_t &index);
    virtual bool recycleOutputBuffer(int32_t index);
    virtual bool recycleInputBuffer(struct v4l2_buffer *qbuf);
    virtual void releaseCodecLock(bool lockable);
    virtual void flush();

private:
    int32_t onQueueBuffer(v4l2_buffer*);
    int32_t onDequeBuffer(v4l2_buffer*);
    int32_t onStreamOn(uint32_t type);
    int32_t onStreamOff(uint32_t type);
    int32_t onRequestBuffers(const v4l2_requestbuffers*);
    int32_t onSetFormat(v4l2_format*);
    int32_t onQueryBuffer(v4l2_buffer*);
    int32_t onSubscribeEvent(v4l2_event_subscription*);
    int32_t onDequeEvent(v4l2_event*);
    int32_t onGetFormat(v4l2_format*);
    int32_t onGetCtrl(v4l2_control*);
    int32_t onEnumFormat(v4l2_fmtdesc*);
    int32_t onGetCrop(v4l2_crop*);
    int32_t onCreateBuffers(v4l2_create_buffers* req);

    //jobs send to decoder thread
    void startDecoderJob();
    void getInputJob();
    void inputReadyJob();
    void getOutputJob();
    void outputReadyJob();
    void checkAllocationJob();
    void flushDecoderJob();

    //tasks send to decoder thread
    int32_t getFormatTask(v4l2_format*);
    int32_t getCtrlTask(v4l2_control*);
    int32_t requestInputBuffers(uint32_t count);

    //help functions
    int32_t sendTask(Task task);
    void post(Job job);
    VideoDecodeBuffer* peekInput();
    void consumeInput();

    bool m_inputOn;
    v4l2_format m_inputFormat;
    std::vector<VideoDecodeBuffer> m_inputFrames;
    std::vector<uint8_t> m_inputSpace;
    BufferPipe<uint32_t> m_in;

    bool m_outputOn;
    v4l2_format m_outputFormat;

    //decoder thread
    Thread m_thread;

    enum State {
        kUnStarted, //decoder thread is not started.
        kWaitAllocation, //wait buffer allocation
        kGetInput,
        kWaitInput,
        kWaitSurface, // wait for surface
        kGetOutput,
        kWaitOutput,
        kFormatChanged, // detected format change. Waiting new surfacee.
        kStopped, // stopped by use
        kError, // have a error
    };
    State m_state;
    SharedPtr<Output> m_output;
    BufferPipe<uint32_t> m_out;
    DisplayPtr m_display;
    DecoderPtr m_decoder;
    std::vector<uint8_t> m_codecData;
};
#endif