Fri, 16 Jan 2015 04:50:19 +0100
Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim:set ts=2 sw=2 sts=2 et cindent: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 5 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | #if !defined(MPAPI_h_) |
michael@0 | 7 | #define MPAPI_h_ |
michael@0 | 8 | |
michael@0 | 9 | #include <stdint.h> |
michael@0 | 10 | |
michael@0 | 11 | namespace MPAPI { |
michael@0 | 12 | |
michael@0 | 13 | enum ColorFormat { |
michael@0 | 14 | I420, |
michael@0 | 15 | RGB565 |
michael@0 | 16 | }; |
michael@0 | 17 | |
michael@0 | 18 | /* |
michael@0 | 19 | * A callback for the plugin to use to request a buffer owned by gecko. This can |
michael@0 | 20 | * save us a copy or two down the line. |
michael@0 | 21 | */ |
michael@0 | 22 | class BufferCallback { |
michael@0 | 23 | public: |
michael@0 | 24 | virtual void *operator()(size_t aWidth, size_t aHeight, |
michael@0 | 25 | ColorFormat aColorFormat) = 0; |
michael@0 | 26 | }; |
michael@0 | 27 | |
michael@0 | 28 | struct VideoPlane { |
michael@0 | 29 | VideoPlane() : |
michael@0 | 30 | mData(0), |
michael@0 | 31 | mStride(0), |
michael@0 | 32 | mWidth(0), |
michael@0 | 33 | mHeight(0), |
michael@0 | 34 | mOffset(0), |
michael@0 | 35 | mSkip(0) |
michael@0 | 36 | {} |
michael@0 | 37 | |
michael@0 | 38 | void *mData; |
michael@0 | 39 | int32_t mStride; |
michael@0 | 40 | int32_t mWidth; |
michael@0 | 41 | int32_t mHeight; |
michael@0 | 42 | int32_t mOffset; |
michael@0 | 43 | int32_t mSkip; |
michael@0 | 44 | }; |
michael@0 | 45 | |
michael@0 | 46 | struct VideoFrame { |
michael@0 | 47 | int64_t mTimeUs; |
michael@0 | 48 | bool mKeyFrame; |
michael@0 | 49 | void *mData; |
michael@0 | 50 | size_t mSize; |
michael@0 | 51 | int32_t mStride; |
michael@0 | 52 | int32_t mSliceHeight; |
michael@0 | 53 | int32_t mRotation; |
michael@0 | 54 | VideoPlane Y; |
michael@0 | 55 | VideoPlane Cb; |
michael@0 | 56 | VideoPlane Cr; |
michael@0 | 57 | |
michael@0 | 58 | VideoFrame() : |
michael@0 | 59 | mTimeUs(0), |
michael@0 | 60 | mKeyFrame(false), |
michael@0 | 61 | mData(0), |
michael@0 | 62 | mSize(0), |
michael@0 | 63 | mStride(0), |
michael@0 | 64 | mSliceHeight(0), |
michael@0 | 65 | mRotation(0) |
michael@0 | 66 | {} |
michael@0 | 67 | |
michael@0 | 68 | void Set(int64_t aTimeUs, bool aKeyFrame, |
michael@0 | 69 | void *aData, size_t aSize, int32_t aStride, int32_t aSliceHeight, int32_t aRotation, |
michael@0 | 70 | void *aYData, int32_t aYStride, int32_t aYWidth, int32_t aYHeight, int32_t aYOffset, int32_t aYSkip, |
michael@0 | 71 | void *aCbData, int32_t aCbStride, int32_t aCbWidth, int32_t aCbHeight, int32_t aCbOffset, int32_t aCbSkip, |
michael@0 | 72 | void *aCrData, int32_t aCrStride, int32_t aCrWidth, int32_t aCrHeight, int32_t aCrOffset, int32_t aCrSkip) |
michael@0 | 73 | { |
michael@0 | 74 | mTimeUs = aTimeUs; |
michael@0 | 75 | mKeyFrame = aKeyFrame; |
michael@0 | 76 | mData = aData; |
michael@0 | 77 | mSize = aSize; |
michael@0 | 78 | mStride = aStride; |
michael@0 | 79 | mSliceHeight = aSliceHeight; |
michael@0 | 80 | mRotation = aRotation; |
michael@0 | 81 | Y.mData = aYData; |
michael@0 | 82 | Y.mStride = aYStride; |
michael@0 | 83 | Y.mWidth = aYWidth; |
michael@0 | 84 | Y.mHeight = aYHeight; |
michael@0 | 85 | Y.mOffset = aYOffset; |
michael@0 | 86 | Y.mSkip = aYSkip; |
michael@0 | 87 | Cb.mData = aCbData; |
michael@0 | 88 | Cb.mStride = aCbStride; |
michael@0 | 89 | Cb.mWidth = aCbWidth; |
michael@0 | 90 | Cb.mHeight = aCbHeight; |
michael@0 | 91 | Cb.mOffset = aCbOffset; |
michael@0 | 92 | Cb.mSkip = aCbSkip; |
michael@0 | 93 | Cr.mData = aCrData; |
michael@0 | 94 | Cr.mStride = aCrStride; |
michael@0 | 95 | Cr.mWidth = aCrWidth; |
michael@0 | 96 | Cr.mHeight = aCrHeight; |
michael@0 | 97 | Cr.mOffset = aCrOffset; |
michael@0 | 98 | Cr.mSkip = aCrSkip; |
michael@0 | 99 | } |
michael@0 | 100 | }; |
michael@0 | 101 | |
michael@0 | 102 | struct AudioFrame { |
michael@0 | 103 | int64_t mTimeUs; |
michael@0 | 104 | void *mData; // 16PCM interleaved |
michael@0 | 105 | size_t mSize; // Size of mData in bytes |
michael@0 | 106 | int32_t mAudioChannels; |
michael@0 | 107 | int32_t mAudioSampleRate; |
michael@0 | 108 | |
michael@0 | 109 | AudioFrame() : |
michael@0 | 110 | mTimeUs(0), |
michael@0 | 111 | mData(0), |
michael@0 | 112 | mSize(0), |
michael@0 | 113 | mAudioChannels(0), |
michael@0 | 114 | mAudioSampleRate(0) |
michael@0 | 115 | { |
michael@0 | 116 | } |
michael@0 | 117 | |
michael@0 | 118 | void Set(int64_t aTimeUs, |
michael@0 | 119 | void *aData, size_t aSize, |
michael@0 | 120 | int32_t aAudioChannels, int32_t aAudioSampleRate) |
michael@0 | 121 | { |
michael@0 | 122 | mTimeUs = aTimeUs; |
michael@0 | 123 | mData = aData; |
michael@0 | 124 | mSize = aSize; |
michael@0 | 125 | mAudioChannels = aAudioChannels; |
michael@0 | 126 | mAudioSampleRate = aAudioSampleRate; |
michael@0 | 127 | } |
michael@0 | 128 | }; |
michael@0 | 129 | |
michael@0 | 130 | struct Decoder; |
michael@0 | 131 | |
michael@0 | 132 | struct PluginHost { |
michael@0 | 133 | bool (*Read)(Decoder *aDecoder, char *aBuffer, int64_t aOffset, uint32_t aCount, uint32_t* aBytes); |
michael@0 | 134 | uint64_t (*GetLength)(Decoder *aDecoder); |
michael@0 | 135 | void (*SetMetaDataReadMode)(Decoder *aDecoder); |
michael@0 | 136 | void (*SetPlaybackReadMode)(Decoder *aDecoder); |
michael@0 | 137 | bool (*GetIntPref)(const char *aPref, int32_t *aResult); |
michael@0 | 138 | bool (*GetSystemInfoString)(const char *aKey, char *aResult, size_t aResultLen); |
michael@0 | 139 | }; |
michael@0 | 140 | |
michael@0 | 141 | struct Decoder { |
michael@0 | 142 | void *mResource; |
michael@0 | 143 | void *mPrivate; |
michael@0 | 144 | |
michael@0 | 145 | Decoder(); |
michael@0 | 146 | |
michael@0 | 147 | void (*GetDuration)(Decoder *aDecoder, int64_t *durationUs); |
michael@0 | 148 | void (*GetVideoParameters)(Decoder *aDecoder, int32_t *aWidth, int32_t *aHeight); |
michael@0 | 149 | void (*GetAudioParameters)(Decoder *aDecoder, int32_t *aNumChannels, int32_t *aSampleRate); |
michael@0 | 150 | bool (*HasVideo)(Decoder *aDecoder); |
michael@0 | 151 | bool (*HasAudio)(Decoder *aDecoder); |
michael@0 | 152 | bool (*ReadVideo)(Decoder *aDecoder, VideoFrame *aFrame, int64_t aSeekTimeUs, BufferCallback *aBufferCallback); |
michael@0 | 153 | bool (*ReadAudio)(Decoder *aDecoder, AudioFrame *aFrame, int64_t aSeekTimeUs); |
michael@0 | 154 | void (*DestroyDecoder)(Decoder *); |
michael@0 | 155 | }; |
michael@0 | 156 | |
michael@0 | 157 | struct Manifest { |
michael@0 | 158 | bool (*CanDecode)(const char *aMimeChars, size_t aMimeLen, const char* const**aCodecs); |
michael@0 | 159 | bool (*CreateDecoder)(PluginHost *aPluginHost, Decoder *aDecoder, |
michael@0 | 160 | const char *aMimeChars, size_t aMimeLen); |
michael@0 | 161 | }; |
michael@0 | 162 | |
michael@0 | 163 | } |
michael@0 | 164 | |
michael@0 | 165 | #endif |