Fri, 16 Jan 2015 18:13:44 +0100
Integrate suggestion from review to improve consistency with existing code.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #if !defined(MPAPI_h_)
7 #define MPAPI_h_
9 #include <stdint.h>
10 #include "mozilla/layers/TextureClient.h"
12 namespace MPAPI {
14 struct VideoPlane {
15 VideoPlane() :
16 mData(nullptr),
17 mStride(0),
18 mWidth(0),
19 mHeight(0),
20 mOffset(0),
21 mSkip(0)
22 {}
24 void *mData;
25 int32_t mStride;
26 int32_t mWidth;
27 int32_t mHeight;
28 int32_t mOffset;
29 int32_t mSkip;
30 };
32 struct VideoFrame {
33 int64_t mTimeUs;
34 bool mKeyFrame;
35 bool mShouldSkip;
36 void *mData;
37 size_t mSize;
38 int32_t mStride;
39 int32_t mSliceHeight;
40 int32_t mRotation;
41 VideoPlane Y;
42 VideoPlane Cb;
43 VideoPlane Cr;
44 mozilla::RefPtr<mozilla::layers::TextureClient> mGraphicBuffer;
46 VideoFrame() :
47 mTimeUs(0),
48 mKeyFrame(false),
49 mShouldSkip(false),
50 mData(nullptr),
51 mSize(0),
52 mStride(0),
53 mSliceHeight(0),
54 mRotation(0)
55 {}
57 void Set(int64_t aTimeUs, bool aKeyFrame,
58 void *aData, size_t aSize, int32_t aStride, int32_t aSliceHeight, int32_t aRotation,
59 void *aYData, int32_t aYStride, int32_t aYWidth, int32_t aYHeight, int32_t aYOffset, int32_t aYSkip,
60 void *aCbData, int32_t aCbStride, int32_t aCbWidth, int32_t aCbHeight, int32_t aCbOffset, int32_t aCbSkip,
61 void *aCrData, int32_t aCrStride, int32_t aCrWidth, int32_t aCrHeight, int32_t aCrOffset, int32_t aCrSkip)
62 {
63 mTimeUs = aTimeUs;
64 mKeyFrame = aKeyFrame;
65 mData = aData;
66 mSize = aSize;
67 mStride = aStride;
68 mSliceHeight = aSliceHeight;
69 mRotation = aRotation;
70 mGraphicBuffer = nullptr;
71 Y.mData = aYData;
72 Y.mStride = aYStride;
73 Y.mWidth = aYWidth;
74 Y.mHeight = aYHeight;
75 Y.mOffset = aYOffset;
76 Y.mSkip = aYSkip;
77 Cb.mData = aCbData;
78 Cb.mStride = aCbStride;
79 Cb.mWidth = aCbWidth;
80 Cb.mHeight = aCbHeight;
81 Cb.mOffset = aCbOffset;
82 Cb.mSkip = aCbSkip;
83 Cr.mData = aCrData;
84 Cr.mStride = aCrStride;
85 Cr.mWidth = aCrWidth;
86 Cr.mHeight = aCrHeight;
87 Cr.mOffset = aCrOffset;
88 Cr.mSkip = aCrSkip;
89 }
90 };
92 struct AudioFrame {
93 int64_t mTimeUs;
94 void *mData; // 16PCM interleaved
95 size_t mSize; // Size of mData in bytes
96 int32_t mAudioChannels;
97 int32_t mAudioSampleRate;
99 AudioFrame() :
100 mTimeUs(0),
101 mData(0),
102 mSize(0),
103 mAudioChannels(0),
104 mAudioSampleRate(0)
105 {
106 }
108 void Set(int64_t aTimeUs,
109 void *aData, size_t aSize,
110 int32_t aAudioChannels, int32_t aAudioSampleRate)
111 {
112 mTimeUs = aTimeUs;
113 mData = aData;
114 mSize = aSize;
115 mAudioChannels = aAudioChannels;
116 mAudioSampleRate = aAudioSampleRate;
117 }
118 };
120 struct Decoder;
122 struct PluginHost {
123 bool (*Read)(Decoder *aDecoder, char *aBuffer, int64_t aOffset, uint32_t aCount, uint32_t* aBytes);
124 uint64_t (*GetLength)(Decoder *aDecoder);
125 void (*SetMetaDataReadMode)(Decoder *aDecoder);
126 void (*SetPlaybackReadMode)(Decoder *aDecoder);
127 };
129 struct Decoder {
130 void *mResource;
131 void *mPrivate;
133 Decoder();
135 void (*GetDuration)(Decoder *aDecoder, int64_t *durationUs);
136 void (*GetVideoParameters)(Decoder *aDecoder, int32_t *aWidth, int32_t *aHeight);
137 void (*GetAudioParameters)(Decoder *aDecoder, int32_t *aNumChannels, int32_t *aSampleRate);
138 bool (*HasVideo)(Decoder *aDecoder);
139 bool (*HasAudio)(Decoder *aDecoder);
140 bool (*ReadVideo)(Decoder *aDecoder, VideoFrame *aFrame, int64_t aSeekTimeUs);
141 bool (*ReadAudio)(Decoder *aDecoder, AudioFrame *aFrame, int64_t aSeekTimeUs);
142 void (*DestroyDecoder)(Decoder *);
143 };
145 struct Manifest {
146 bool (*CanDecode)(const char *aMimeChars, size_t aMimeLen, const char* const**aCodecs);
147 bool (*CreateDecoder)(PluginHost *aPluginHost, Decoder *aDecoder,
148 const char *aMimeChars, size_t aMimeLen);
149 };
151 }
153 #endif