• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2019 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #include "experimental/ffmpeg/SkVideoDecoder.h"
9 #include "gm/gm.h"
10 #include "include/core/SkCanvas.h"
11 #include "include/core/SkStream.h"
12 
13 class VideoDecoderGM : public skiagm::GM {
14     SkVideoDecoder fDecoder;
15 
16 public:
VideoDecoderGM()17     VideoDecoderGM() {}
18 
19 protected:
20 
onShortName()21     SkString onShortName() override {
22         return SkString("videodecoder");
23     }
24 
onISize()25     SkISize onISize() override {
26         return SkISize::Make(1024, 768);
27     }
28 
onOnceBeforeDraw()29     void onOnceBeforeDraw() override {
30         if (!fDecoder.loadStream(SkStream::MakeFromFile("/skia/ice.mp4"))) {
31             SkDebugf("could not load movie file\n");
32         }
33         SkDebugf("duration %g\n", fDecoder.duration());
34     }
35 
onDraw(SkCanvas * canvas)36     void onDraw(SkCanvas* canvas) override {
37         auto* rContext = canvas->recordingContext();
38         if (!rContext) {
39             return;
40         }
41 
42         fDecoder.setGrContext(rContext);  // context can change over time in viewer
43 
44         double timeStamp;
45         auto img = fDecoder.nextImage(&timeStamp);
46         if (!img) {
47             (void)fDecoder.rewind();
48             img = fDecoder.nextImage(&timeStamp);
49         }
50         if (img) {
51             if (0) {
52                 SkDebugf("ts %g\n", timeStamp);
53             }
54             canvas->drawImage(img, 10, 10);
55         }
56     }
57 
onAnimate(double nanos)58     bool onAnimate(double nanos) override {
59         return true;
60     }
61 
62 private:
63     using INHERITED = GM;
64 };
65 DEF_GM( return new VideoDecoderGM; )
66 
67