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
|
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef WEBRTC_GONK
#pragma error WebrtcOMXH264VideoCodec works only on B2G.
#endif
#ifndef WEBRTC_OMX_H264_CODEC_H_
#define WEBRTC_OMX_H264_CODEC_H_
#include "AudioConduit.h"
#include "VideoConduit.h"
#include <foundation/ABase.h>
#include <utils/RefBase.h>
#include "OMXCodecWrapper.h"
namespace android {
class OMXVideoEncoder;
}
namespace mozilla {
class WebrtcOMXDecoder;
class OMXOutputDrain;
// XXX see if we can reduce this
#define WEBRTC_OMX_H264_MIN_DECODE_BUFFERS 10
#define OMX_IDR_NEEDED_FOR_BITRATE 0
class WebrtcOMXH264VideoEncoder : public WebrtcVideoEncoder
{
public:
WebrtcOMXH264VideoEncoder();
virtual ~WebrtcOMXH264VideoEncoder();
// Implement VideoEncoder interface.
virtual uint64_t PluginID() const override { return 0; }
virtual int32_t InitEncode(const webrtc::VideoCodec* aCodecSettings,
int32_t aNumOfCores,
size_t aMaxPayloadSize) override;
virtual int32_t Encode(const webrtc::I420VideoFrame& aInputImage,
const webrtc::CodecSpecificInfo* aCodecSpecificInfo,
const std::vector<webrtc::VideoFrameType>* aFrameTypes) override;
virtual int32_t RegisterEncodeCompleteCallback(webrtc::EncodedImageCallback* aCallback) override;
virtual int32_t Release() override;
virtual int32_t SetChannelParameters(uint32_t aPacketLossRate,
int64_t aRoundTripTimeMs) override;
virtual int32_t SetRates(uint32_t aBitRate, uint32_t aFrameRate) override;
private:
nsAutoPtr<android::OMXVideoEncoder> mOMX;
android::sp<android::OMXCodecReservation> mReservation;
webrtc::EncodedImageCallback* mCallback;
RefPtr<OMXOutputDrain> mOutputDrain;
uint32_t mWidth;
uint32_t mHeight;
uint32_t mFrameRate;
uint32_t mBitRateKbps;
#ifdef OMX_IDR_NEEDED_FOR_BITRATE
uint32_t mBitRateAtLastIDR;
TimeStamp mLastIDRTime;
#endif
bool mOMXConfigured;
bool mOMXReconfigure;
webrtc::EncodedImage mEncodedImage;
};
class WebrtcOMXH264VideoDecoder : public WebrtcVideoDecoder
{
public:
WebrtcOMXH264VideoDecoder();
virtual ~WebrtcOMXH264VideoDecoder();
// Implement VideoDecoder interface.
virtual uint64_t PluginID() const override { return 0; }
virtual int32_t InitDecode(const webrtc::VideoCodec* aCodecSettings,
int32_t aNumOfCores) override;
virtual int32_t Decode(const webrtc::EncodedImage& aInputImage,
bool aMissingFrames,
const webrtc::RTPFragmentationHeader* aFragmentation,
const webrtc::CodecSpecificInfo* aCodecSpecificInfo = nullptr,
int64_t aRenderTimeMs = -1) override;
virtual int32_t RegisterDecodeCompleteCallback(webrtc::DecodedImageCallback* callback) override;
virtual int32_t Release() override;
virtual int32_t Reset() override;
private:
webrtc::DecodedImageCallback* mCallback;
RefPtr<WebrtcOMXDecoder> mOMX;
android::sp<android::OMXCodecReservation> mReservation;
};
}
#endif // WEBRTC_OMX_H264_CODEC_H_
|