summaryrefslogtreecommitdiff
path: root/service/src/com/android/telephony/imsmedia/lib/libimsmedia/core/include/video/nodes/IVideoRendererNode.h
blob: 3e4483e7ec34bba242bc30dd3ec39963c3b49ed7 (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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/**
 * Copyright (C) 2022 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 IVIDEO_RENDERER_NODE_H_INCLUDED
#define IVIDEO_RENDERER_NODE_H_INCLUDED

#include <BaseNode.h>
#include <JitterBufferControlNode.h>
#include <IImsMediaThread.h>
#include <ImsMediaCondition.h>
#include <ImsMediaVideoRenderer.h>
#include <ImsMediaVideoUtil.h>
#include <android/native_window.h>
#include <mutex>

#define USE_JITTER_BUFFER  // off this definition ONLY for test purpose.
#define DEMON_NTP2MSEC 65.55

enum FrameType
{
    UNKNOWN,
    SPS,
    PPS,
    VPS,
    IDR,
    NonIDR,
};

/**
 * @brief This class describes an interface between depacketization module and audio device
 */
class IVideoRendererNode : public JitterBufferControlNode
{
public:
    IVideoRendererNode(BaseSessionCallback* callback = nullptr);
    virtual ~IVideoRendererNode();
    virtual kBaseNodeId GetNodeId();
    virtual ImsMediaResult Start();
    virtual void Stop();
    virtual bool IsRunTime();
    virtual bool IsSourceNode();
    virtual void SetConfig(void* config);
    virtual bool IsSameConfig(void* config);
    virtual void ProcessData();

    /**
     * @brief Updates display surface
     *
     * @param window surface buffer to update
     */
    void UpdateSurface(ANativeWindow* window);

    /**
     * @brief Update network round trip time delay to the VideoJitterBuffer
     *
     * @param delay time delay in ntp timestamp unit
     */
    void UpdateRoundTripTimeDelay(int32_t delay);

    /**
     * @brief Set the packet loss monitoring duration and packet loss rate threshold
     *
     * @param time The time duration of milliseconds unit to monitor the packet loss
     * @param rate The packet loss rate threshold in the monitoring duration range
     */
    void SetPacketLossParam(uint32_t time, uint32_t rate);

private:
    bool hasStartingCode(uint8_t* buffer, uint32_t bufferSize);
    FrameType GetFrameType(uint8_t* buffer, uint32_t bufferSize);
    void SaveConfigFrame(uint8_t* buffer, uint32_t bufferSize, uint32_t type);

    /**
     * @brief Remove Access Uint Delimiter Nal Unit.
     *
     * @param inBuffer
     * @param ibufferSize
     * @param outBuffer
     * @param outBufferSize
     * @return true
     * @return false
     */
    bool RemoveAUDNalUnit(
            uint8_t* inBuffer, uint32_t ibufferSize, uint8_t** outBuffer, uint32_t* outBufferSize);
    void CheckResolution(uint32_t nWidth, uint32_t nHeight);
    ImsMediaResult ParseAvcSps(uint8_t* buffer, uint32_t bufferSize, tCodecConfig* config);
    ImsMediaResult ParseHevcSps(uint8_t* buffer, uint32_t bufferSize, tCodecConfig* config);
    void QueueConfigFrame(uint32_t timestamp);
    void NotifyPeerDimensionChanged();

    std::unique_ptr<ImsMediaVideoRenderer> mVideoRenderer;
    ANativeWindow* mWindow;
    ImsMediaCondition mCondition;
    std::mutex mMutex;
    int32_t mCodecType;
    uint32_t mWidth;
    uint32_t mHeight;
    int8_t mSamplingRate;
    int32_t mCvoValue;
    uint8_t mConfigBuffer[MAX_CONFIG_INDEX][MAX_CONFIG_LEN];
    uint32_t mConfigLen[MAX_CONFIG_INDEX];
    uint8_t mBuffer[MAX_RTP_PAYLOAD_BUFFER_SIZE];
    uint32_t mDeviceOrientation;
    bool mFirstFrame;
    ImsMediaSubType mSubtype;
    uint32_t mFramerate;
    uint32_t mLossDuration;
    uint32_t mLossRateThreshold;
};

#endif