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: getName() const20 SkString getName() const override { return SkString("videodecoder"); } 21 getISize()22 SkISize getISize() override { return SkISize::Make(1024, 768); } 23 onOnceBeforeDraw()24 void onOnceBeforeDraw() override { 25 if (!fDecoder.loadStream(SkStream::MakeFromFile("/skia/ice.mp4"))) { 26 SkDebugf("could not load movie file\n"); 27 } 28 SkDebugf("duration %g\n", fDecoder.duration()); 29 } 30 onDraw(SkCanvas * canvas)31 void onDraw(SkCanvas* canvas) override { 32 auto* rContext = canvas->recordingContext(); 33 if (!rContext) { 34 return; 35 } 36 37 fDecoder.setGrContext(rContext); // context can change over time in viewer 38 39 double timeStamp; 40 auto img = fDecoder.nextImage(&timeStamp); 41 if (!img) { 42 (void)fDecoder.rewind(); 43 img = fDecoder.nextImage(&timeStamp); 44 } 45 if (img) { 46 if (0) { 47 SkDebugf("ts %g\n", timeStamp); 48 } 49 canvas->drawImage(img, 10, 10); 50 } 51 } 52 onAnimate(double nanos)53 bool onAnimate(double nanos) override { 54 return true; 55 } 56 57 private: 58 using INHERITED = GM; 59 }; 60 DEF_GM( return new VideoDecoderGM; ) 61 62