content/media/plugins/MPAPI.h

Fri, 16 Jan 2015 04:50:19 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 04:50:19 +0100
branch
TOR_BUG_9701
changeset 13
44a2da4a2ab2
permissions
-rw-r--r--

Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32

     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>
    11 namespace MPAPI {
    13 enum ColorFormat {
    14   I420,
    15   RGB565
    16 };
    18 /*
    19  * A callback for the plugin to use to request a buffer owned by gecko. This can
    20  * save us a copy or two down the line.
    21  */
    22 class BufferCallback {
    23 public:
    24   virtual void *operator()(size_t aWidth, size_t aHeight,
    25                            ColorFormat aColorFormat) = 0;
    26 };
    28 struct VideoPlane {
    29   VideoPlane() :
    30     mData(0),
    31     mStride(0),
    32     mWidth(0),
    33     mHeight(0),
    34     mOffset(0),
    35     mSkip(0)
    36   {}
    38   void *mData;
    39   int32_t mStride;
    40   int32_t mWidth;
    41   int32_t mHeight;
    42   int32_t mOffset;
    43   int32_t mSkip;
    44 };
    46 struct VideoFrame {
    47   int64_t mTimeUs;
    48   bool mKeyFrame;
    49   void *mData;
    50   size_t mSize;
    51   int32_t mStride;
    52   int32_t mSliceHeight;
    53   int32_t mRotation;
    54   VideoPlane Y;
    55   VideoPlane Cb;
    56   VideoPlane Cr;
    58   VideoFrame() :
    59     mTimeUs(0),
    60     mKeyFrame(false),
    61     mData(0),
    62     mSize(0),
    63     mStride(0),
    64     mSliceHeight(0),
    65     mRotation(0)
    66   {}
    68   void Set(int64_t aTimeUs, bool aKeyFrame,
    69            void *aData, size_t aSize, int32_t aStride, int32_t aSliceHeight, int32_t aRotation,
    70            void *aYData, int32_t aYStride, int32_t aYWidth, int32_t aYHeight, int32_t aYOffset, int32_t aYSkip,
    71            void *aCbData, int32_t aCbStride, int32_t aCbWidth, int32_t aCbHeight, int32_t aCbOffset, int32_t aCbSkip,
    72            void *aCrData, int32_t aCrStride, int32_t aCrWidth, int32_t aCrHeight, int32_t aCrOffset, int32_t aCrSkip)
    73   {
    74     mTimeUs = aTimeUs;
    75     mKeyFrame = aKeyFrame;
    76     mData = aData;
    77     mSize = aSize;
    78     mStride = aStride;
    79     mSliceHeight = aSliceHeight;
    80     mRotation = aRotation;
    81     Y.mData = aYData;
    82     Y.mStride = aYStride;
    83     Y.mWidth = aYWidth;
    84     Y.mHeight = aYHeight;
    85     Y.mOffset = aYOffset;
    86     Y.mSkip = aYSkip;
    87     Cb.mData = aCbData;
    88     Cb.mStride = aCbStride;
    89     Cb.mWidth = aCbWidth;
    90     Cb.mHeight = aCbHeight;
    91     Cb.mOffset = aCbOffset;
    92     Cb.mSkip = aCbSkip;
    93     Cr.mData = aCrData;
    94     Cr.mStride = aCrStride;
    95     Cr.mWidth = aCrWidth;
    96     Cr.mHeight = aCrHeight;
    97     Cr.mOffset = aCrOffset;
    98     Cr.mSkip = aCrSkip;
    99   }
   100 };
   102 struct AudioFrame {
   103   int64_t mTimeUs;
   104   void *mData; // 16PCM interleaved
   105   size_t mSize; // Size of mData in bytes
   106   int32_t mAudioChannels;
   107   int32_t mAudioSampleRate;
   109   AudioFrame() :
   110     mTimeUs(0),
   111     mData(0),
   112     mSize(0),
   113     mAudioChannels(0),
   114     mAudioSampleRate(0)
   115   {
   116   }
   118   void Set(int64_t aTimeUs,
   119            void *aData, size_t aSize,
   120            int32_t aAudioChannels, int32_t aAudioSampleRate)
   121   {
   122     mTimeUs = aTimeUs;
   123     mData = aData;
   124     mSize = aSize;
   125     mAudioChannels = aAudioChannels;
   126     mAudioSampleRate = aAudioSampleRate;
   127   }
   128 };
   130 struct Decoder;
   132 struct PluginHost {
   133   bool (*Read)(Decoder *aDecoder, char *aBuffer, int64_t aOffset, uint32_t aCount, uint32_t* aBytes);
   134   uint64_t (*GetLength)(Decoder *aDecoder);
   135   void (*SetMetaDataReadMode)(Decoder *aDecoder);
   136   void (*SetPlaybackReadMode)(Decoder *aDecoder);
   137   bool (*GetIntPref)(const char *aPref, int32_t *aResult);
   138   bool (*GetSystemInfoString)(const char *aKey, char *aResult, size_t aResultLen);
   139 };
   141 struct Decoder {
   142   void *mResource;
   143   void *mPrivate;
   145   Decoder();
   147   void (*GetDuration)(Decoder *aDecoder, int64_t *durationUs);
   148   void (*GetVideoParameters)(Decoder *aDecoder, int32_t *aWidth, int32_t *aHeight);
   149   void (*GetAudioParameters)(Decoder *aDecoder, int32_t *aNumChannels, int32_t *aSampleRate);
   150   bool (*HasVideo)(Decoder *aDecoder);
   151   bool (*HasAudio)(Decoder *aDecoder);
   152   bool (*ReadVideo)(Decoder *aDecoder, VideoFrame *aFrame, int64_t aSeekTimeUs, BufferCallback *aBufferCallback);
   153   bool (*ReadAudio)(Decoder *aDecoder, AudioFrame *aFrame, int64_t aSeekTimeUs);
   154   void (*DestroyDecoder)(Decoder *);
   155 };
   157 struct Manifest {
   158   bool (*CanDecode)(const char *aMimeChars, size_t aMimeLen, const char* const**aCodecs);
   159   bool (*CreateDecoder)(PluginHost *aPluginHost, Decoder *aDecoder,
   160                         const char *aMimeChars, size_t aMimeLen);
   161 };
   163 }
   165 #endif

mercurial