]> git.pld-linux.org Git - packages/openh264.git/blob - openh264-firefox33.patch
- added firefox33 patch, build GMP plugin
[packages/openh264.git] / openh264-firefox33.patch
1 From 1acb0fb89fed6178057eccb28730bc4156746826 Mon Sep 17 00:00:00 2001
2 From: Ethan Hugg <ethanhugg@gmail.com>
3 Date: Fri, 11 Jul 2014 08:29:02 -0700
4 Subject: [PATCH] Updated to match gmp-api changes for Firefox33
5
6 ---
7  module/gmp-openh264.cpp | 159 +++++++++++++++++++++++++++++-------------------
8  module/task_utils.h     |   3 +
9  2 files changed, 101 insertions(+), 61 deletions(-)
10
11 diff --git a/module/gmp-openh264.cpp b/module/gmp-openh264.cpp
12 index a70e883..5996ac8 100644
13 --- a/module/gmp-openh264.cpp
14 +++ b/module/gmp-openh264.cpp
15 @@ -190,19 +190,21 @@ class OpenH264VideoEncoder : public GMPVideoEncoder {
16      worker_thread_->Join();
17    }
18  
19 -  virtual GMPVideoErr InitEncode (const GMPVideoCodec& codecSettings,
20 -                                  GMPEncoderCallback* callback,
21 -                                  int32_t numberOfCores,
22 -                                  uint32_t maxPayloadSize) {
23 +  virtual GMPErr InitEncode (const GMPVideoCodec& codecSettings,
24 +                             const uint8_t* aCodecSpecific,
25 +                             uint32_t aCodecSpecificSize,
26 +                             GMPVideoEncoderCallback* callback,
27 +                             int32_t numberOfCores,
28 +                             uint32_t maxPayloadSize) {
29      GMPErr err = g_platform_api->createthread (&worker_thread_);
30      if (err != GMPNoErr) {
31        GMPLOG (GL_ERROR, "Couldn't create new thread");
32 -      return GMPVideoGenericErr;
33 +      return GMPGenericErr;
34      }
35  
36      int rv = WelsCreateSVCEncoder (&encoder_);
37      if (rv) {
38 -      return GMPVideoGenericErr;
39 +      return GMPGenericErr;
40      }
41  
42      SEncParamBase param;
43 @@ -236,7 +238,7 @@ class OpenH264VideoEncoder : public GMPVideoEncoder {
44      rv = encoder_->Initialize (&param);
45      if (rv) {
46        GMPLOG (GL_ERROR, "Couldn't initialize encoder");
47 -      return GMPVideoGenericErr;
48 +      return GMPGenericErr;
49      }
50  
51      max_payload_size_ = maxPayloadSize;
52 @@ -244,12 +246,14 @@ class OpenH264VideoEncoder : public GMPVideoEncoder {
53  
54      GMPLOG (GL_INFO, "Initialized encoder");
55  
56 -    return GMPVideoNoErr;
57 +    return GMPNoErr;
58    }
59  
60 -  virtual GMPVideoErr Encode (GMPVideoi420Frame* inputImage,
61 -                              const GMPCodecSpecificInfo& codecSpecificInfo,
62 -                              const std::vector<GMPVideoFrameType>& frameTypes) {
63 +  virtual GMPErr Encode (GMPVideoi420Frame* inputImage,
64 +                         const uint8_t* aCodecSpecificInfo,
65 +                         uint32_t aCodecSpecificInfoLength,
66 +                         const GMPVideoFrameType* aFrameTypes,
67 +                         uint32_t aFrameTypesLength) {
68      GMPLOG (GL_DEBUG,
69              __FUNCTION__
70              << " size="
71 @@ -257,19 +261,14 @@ class OpenH264VideoEncoder : public GMPVideoEncoder {
72  
73      stats_.FrameIn();
74  
75 -    assert (!frameTypes.empty());
76 -    if (frameTypes.empty()) {
77 -      GMPLOG (GL_ERROR, "No frame types provided");
78 -      inputImage->Destroy();
79 -      return GMPVideoGenericErr;
80 -    }
81 +    assert (aFrameTypesLength != 0);
82  
83      worker_thread_->Post (WrapTask (
84                              this, &OpenH264VideoEncoder::Encode_w,
85                              inputImage,
86 -                            (frameTypes)[0]));
87 +                            (aFrameTypes)[0]));
88  
89 -    return GMPVideoGenericErr;
90 +    return GMPGenericErr;
91    }
92  
93    void Encode_w (GMPVideoi420Frame* inputImage,
94 @@ -363,8 +362,8 @@ class OpenH264VideoEncoder : public GMPVideoEncoder {
95                   GMPVideoFrameType frame_type) {
96      // Now return the encoded data back to the parent.
97      GMPVideoFrame* ftmp;
98 -    GMPVideoErr err = host_->CreateFrame (kGMPEncodedVideoFrame, &ftmp);
99 -    if (err != GMPVideoNoErr) {
100 +    GMPErr err = host_->CreateFrame (kGMPEncodedVideoFrame, &ftmp);
101 +    if (err != GMPNoErr) {
102        GMPLOG (GL_ERROR, "Error creating encoded frame");
103        frame->Destroy();
104        return;
105 @@ -377,17 +376,20 @@ class OpenH264VideoEncoder : public GMPVideoEncoder {
106  
107      for (int i = 0; i < encoded->iLayerNum; ++i) {
108        lengths.push_back (0);
109 +      uint8_t *tmp = encoded->sLayerInfo[i].pBsBuf;
110        for (int j = 0; j < encoded->sLayerInfo[i].iNalCount; ++j) {
111          lengths[i] += encoded->sLayerInfo[i].pNalLengthInByte[j];
112 +        // Convert from 4-byte start codes to GMP_BufferLength32 (NAL lengths)
113 +        assert(*(reinterpret_cast<uint32_t *>(tmp)) == 0x01000000);
114 +        // BufferType32 doesn't include the length of the length itself!
115 +        *(reinterpret_cast<uint32_t *>(tmp)) = encoded->sLayerInfo[i].pNalLengthInByte[j] - sizeof(uint32_t);
116          length += encoded->sLayerInfo[i].pNalLengthInByte[j];
117 +        tmp += encoded->sLayerInfo[i].pNalLengthInByte[j];
118        }
119      }
120  
121 -    // TODO start-code to length conversion here when gmp
122 -    // stops doing it for us before this call.
123 -
124      err = f->CreateEmptyFrame (length);
125 -    if (err != GMPVideoNoErr) {
126 +    if (err != GMPNoErr) {
127        GMPLOG (GL_ERROR, "Error allocating frame data");
128        f->Destroy();
129        frame->Destroy();
130 @@ -407,6 +409,7 @@ class OpenH264VideoEncoder : public GMPVideoEncoder {
131      f->SetTimeStamp (frame->Timestamp());
132      f->SetFrameType (frame_type);
133      f->SetCompleteFrame (true);
134 +    f->SetBufferType (GMP_BufferLength32);
135  
136      GMPLOG (GL_DEBUG, "Encoding complete. type= "
137              << f->FrameType()
138 @@ -420,9 +423,12 @@ class OpenH264VideoEncoder : public GMPVideoEncoder {
139  
140      // Return the encoded frame.
141      GMPCodecSpecificInfo info;
142 -    memset (&info, 0, sizeof (info));
143 -    // TODO need to set what goes in this info structure.
144 -    callback_->Encoded (f, info);
145 +    memset (&info, 0, sizeof (info)); // shouldn't be needed, we init everything
146 +    info.mCodecType = kGMPVideoCodecH264;
147 +    info.mBufferType = GMP_BufferLength32;
148 +    info.mCodecSpecific.mH264.mSimulcastIdx = 0;
149 +
150 +    callback_->Encoded (f, reinterpret_cast<uint8_t*>(&info), sizeof(info));
151  
152      stats_.FrameOut();
153    }
154 @@ -432,11 +438,11 @@ class OpenH264VideoEncoder : public GMPVideoEncoder {
155      frame->Destroy();
156    }
157  
158 -  virtual GMPVideoErr SetChannelParameters (uint32_t aPacketLoss, uint32_t aRTT) {
159 -    return GMPVideoNoErr;
160 +  virtual GMPErr SetChannelParameters (uint32_t aPacketLoss, uint32_t aRTT) {
161 +    return GMPNoErr;
162    }
163  
164 -  virtual GMPVideoErr SetRates (uint32_t aNewBitRate, uint32_t aFrameRate) {
165 +  virtual GMPErr SetRates (uint32_t aNewBitRate, uint32_t aFrameRate) {
166      GMPLOG (GL_INFO, "[SetRates] Begin with: "
167              << aNewBitRate << " , " << aFrameRate);
168      //update bitrate if needed
169 @@ -451,7 +457,7 @@ class OpenH264VideoEncoder : public GMPVideoEncoder {
170                << existEncoderBitRate.iLayer
171                << " ; BR = "
172                << existEncoderBitRate.iBitrate);
173 -      return GMPVideoGenericErr;
174 +      return GMPGenericErr;
175      }
176      if (rv == cmResultSuccess && existEncoderBitRate.iBitrate != newBitRate) {
177        SBitrateInfo newEncoderBitRate;
178 @@ -470,7 +476,7 @@ class OpenH264VideoEncoder : public GMPVideoEncoder {
179                  << newEncoderBitRate.iLayer
180                  << " ; BR = "
181                  << newEncoderBitRate.iBitrate);
182 -        return GMPVideoGenericErr;
183 +        return GMPGenericErr;
184        }
185      }
186      //update framerate if needed
187 @@ -479,7 +485,7 @@ class OpenH264VideoEncoder : public GMPVideoEncoder {
188      if (rv != cmResultSuccess) {
189        GMPLOG (GL_ERROR, "[SetRates] Error in Getting Frame Rate:"
190                << rv << " FrameRate: " << existFrameRate);
191 -      return GMPVideoGenericErr;
192 +      return GMPGenericErr;
193      }
194      if (rv == cmResultSuccess &&
195          (aFrameRate - existFrameRate > 0.001f ||
196 @@ -492,14 +498,14 @@ class OpenH264VideoEncoder : public GMPVideoEncoder {
197        } else {
198          GMPLOG (GL_ERROR, "[SetRates] Error in Setting Frame Rate: ReturnValue: "
199                  << rv << " FrameRate: " << aFrameRate);
200 -        return GMPVideoGenericErr;
201 +        return GMPGenericErr;
202        }
203      }
204 -    return GMPVideoNoErr;
205 +    return GMPNoErr;
206    }
207  
208 -  virtual GMPVideoErr SetPeriodicKeyFrames (bool aEnable) {
209 -    return GMPVideoNoErr;
210 +  virtual GMPErr SetPeriodicKeyFrames (bool aEnable) {
211 +    return GMPNoErr;
212    }
213  
214    virtual void EncodingComplete() {
215 @@ -511,7 +517,7 @@ class OpenH264VideoEncoder : public GMPVideoEncoder {
216    GMPThread* worker_thread_;
217    ISVCEncoder* encoder_;
218    uint32_t max_payload_size_;
219 -  GMPEncoderCallback* callback_;
220 +  GMPVideoEncoderCallback* callback_;
221    FrameStats stats_;
222  };
223  
224 @@ -527,25 +533,27 @@ class OpenH264VideoDecoder : public GMPVideoDecoder {
225    virtual ~OpenH264VideoDecoder() {
226    }
227  
228 -  virtual GMPVideoErr InitDecode (const GMPVideoCodec& codecSettings,
229 -                                  GMPDecoderCallback* callback,
230 -                                  int32_t coreCount) {
231 +  virtual GMPErr InitDecode (const GMPVideoCodec& codecSettings,
232 +                             const uint8_t* aCodecSpecific,
233 +                             uint32_t aCodecSpecificSize,
234 +                             GMPVideoDecoderCallback* callback,
235 +                             int32_t coreCount) {
236      GMPLOG (GL_INFO, "InitDecode");
237  
238      GMPErr err = g_platform_api->createthread (&worker_thread_);
239      if (err != GMPNoErr) {
240        GMPLOG (GL_ERROR, "Couldn't create new thread");
241 -      return GMPVideoGenericErr;
242 +      return GMPGenericErr;
243      }
244  
245      if (WelsCreateDecoder (&decoder_)) {
246        GMPLOG (GL_ERROR, "Couldn't create decoder");
247 -      return GMPVideoGenericErr;
248 +      return GMPGenericErr;
249      }
250  
251      if (!decoder_) {
252        GMPLOG (GL_ERROR, "Couldn't create decoder");
253 -      return GMPVideoGenericErr;
254 +      return GMPGenericErr;
255      }
256  
257      SDecodingParam param;
258 @@ -557,21 +565,50 @@ class OpenH264VideoDecoder : public GMPVideoDecoder {
259  
260      if (decoder_->Initialize (&param)) {
261        GMPLOG (GL_ERROR, "Couldn't initialize decoder");
262 -      return GMPVideoGenericErr;
263 +      return GMPGenericErr;
264      }
265  
266      callback_ = callback;
267 -    return GMPVideoNoErr;
268 +    return GMPNoErr;
269    }
270  
271 -  virtual GMPVideoErr Decode (GMPVideoEncodedFrame* inputFrame,
272 -                              bool missingFrames,
273 -                              const GMPCodecSpecificInfo& codecSpecificInfo,
274 -                              int64_t renderTimeMs = -1) {
275 +  virtual GMPErr Decode (GMPVideoEncodedFrame* inputFrame,
276 +                         bool missingFrames,
277 +                         const uint8_t* aCodecSpecificInfo,
278 +                         uint32_t aCodecSpecificInfoLength,
279 +                         int64_t renderTimeMs = -1) {
280      GMPLOG (GL_DEBUG, __FUNCTION__
281              << "Decoding frame size=" << inputFrame->Size()
282              << " timestamp=" << inputFrame->TimeStamp());
283      stats_.FrameIn();
284 +    //const GMPCodecSpecificInfo *codecSpecificInfo = (GMPCodecSpecificInfo) aCodecSpecificInfo;
285 +
286 +    // Convert to H.264 start codes
287 +    switch (inputFrame->BufferType()) {
288 +      case GMP_BufferSingle:
289 +      case GMP_BufferLength8:
290 +      case GMP_BufferLength16:
291 +      case GMP_BufferLength24:
292 +        // We should look to support these, especially GMP_BufferSingle
293 +        assert(false);
294 +        break;
295 +
296 +      case GMP_BufferLength32:
297 +        {
298 +          uint8_t *start_code = inputFrame->Buffer();
299 +          while (start_code < inputFrame->Buffer() + inputFrame->Size()) {
300 +            static const uint8_t code[] = { 0x00, 0x00, 0x00, 0x01 };
301 +            uint8_t *lenp = start_code;
302 +            start_code += *(reinterpret_cast<int32_t *>(lenp));
303 +            memcpy(lenp, code, 4);
304 +          }
305 +        }
306 +        break;
307 +
308 +      default:
309 +        assert(false);
310 +        break;
311 +    }
312  
313      worker_thread_->Post (WrapTask (
314                              this, &OpenH264VideoDecoder::Decode_w,
315 @@ -579,15 +616,15 @@ class OpenH264VideoDecoder : public GMPVideoDecoder {
316                              missingFrames,
317                              renderTimeMs));
318  
319 -    return GMPVideoNoErr;
320 +    return GMPNoErr;
321    }
322  
323 -  virtual GMPVideoErr Reset() {
324 -    return GMPVideoNoErr;
325 +  virtual GMPErr Reset() {
326 +    return GMPNoErr;
327    }
328  
329 -  virtual GMPVideoErr Drain() {
330 -    return GMPVideoNoErr;
331 +  virtual GMPErr Drain() {
332 +    return GMPNoErr;
333    }
334  
335    virtual void DecodingComplete() {
336 @@ -660,8 +697,8 @@ class OpenH264VideoDecoder : public GMPVideoDecoder {
337      GMPVideoFrame* ftmp = nullptr;
338  
339      // Translate the image.
340 -    GMPVideoErr err = host_->CreateFrame (kGMPI420VideoFrame, &ftmp);
341 -    if (err != GMPVideoNoErr) {
342 +    GMPErr err = host_->CreateFrame (kGMPI420VideoFrame, &ftmp);
343 +    if (err != GMPNoErr) {
344        GMPLOG (GL_ERROR, "Couldn't allocate empty I420 frame");
345        return;
346      }
347 @@ -674,7 +711,7 @@ class OpenH264VideoDecoder : public GMPVideoDecoder {
348              uvstride * height / 2, static_cast<uint8_t*> (data[2]),
349              width, height,
350              ystride, uvstride, uvstride);
351 -    if (err != GMPVideoNoErr) {
352 +    if (err != GMPNoErr) {
353        GMPLOG (GL_ERROR, "Couldn't make decoded frame");
354        return;
355      }
356 @@ -682,7 +719,7 @@ class OpenH264VideoDecoder : public GMPVideoDecoder {
357      GMPLOG (GL_DEBUG, "Allocated size = "
358              << frame->AllocatedSize (kGMPYPlane));
359      frame->SetTimestamp (inputFrame->TimeStamp());
360 -    frame->SetRenderTime_ms (renderTimeMs);
361 +    frame->SetDuration (inputFrame->Duration());
362      callback_->Decoded (frame);
363  
364      stats_.FrameOut();
365 @@ -690,7 +727,7 @@ class OpenH264VideoDecoder : public GMPVideoDecoder {
366  
367    GMPVideoHost* host_;
368    GMPThread* worker_thread_;
369 -  GMPDecoderCallback* callback_;
370 +  GMPVideoDecoderCallback* callback_;
371    ISVCDecoder* decoder_;
372    FrameStats stats_;
373  };
374 diff --git a/module/task_utils.h b/module/task_utils.h
375 index 2bd8937..c53e8d4 100644
376 --- a/module/task_utils.h
377 +++ b/module/task_utils.h
378 @@ -13,6 +13,9 @@
379  class gmp_args_base : public GMPTask {
380   public:
381    void Run() = 0;
382 +  void Destroy() {
383 +    delete this;
384 +  }
385  };
386  
387  // The generated file contains four major function templates
This page took 0.103246 seconds and 3 git commands to generate.