video_decoder.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. #include "experimental/ffmpeg/SkVideoDecoder.h"
  8. #include "gm/gm.h"
  9. #include "include/core/SkCanvas.h"
  10. #include "include/core/SkStream.h"
  11. class VideoDecoderGM : public skiagm::GM {
  12. SkVideoDecoder fDecoder;
  13. public:
  14. VideoDecoderGM() {}
  15. protected:
  16. SkString onShortName() override {
  17. return SkString("videodecoder");
  18. }
  19. SkISize onISize() override {
  20. return SkISize::Make(1024, 768);
  21. }
  22. void onOnceBeforeDraw() override {
  23. if (!fDecoder.loadStream(SkStream::MakeFromFile("/skia/ice.mp4"))) {
  24. SkDebugf("could not load movie file\n");
  25. }
  26. SkDebugf("duration %g\n", fDecoder.duration());
  27. }
  28. void onDraw(SkCanvas* canvas) override {
  29. GrContext* gr = canvas->getGrContext();
  30. if (!gr) {
  31. return;
  32. }
  33. fDecoder.setGrContext(gr); // gr can change over time in viewer
  34. double timeStamp;
  35. auto img = fDecoder.nextImage(&timeStamp);
  36. if (!img) {
  37. (void)fDecoder.rewind();
  38. img = fDecoder.nextImage(&timeStamp);
  39. }
  40. if (img) {
  41. if (0) {
  42. SkDebugf("ts %g\n", timeStamp);
  43. }
  44. canvas->drawImage(img, 10, 10, nullptr);
  45. }
  46. }
  47. bool onAnimate(double nanos) override {
  48. return true;
  49. }
  50. private:
  51. typedef GM INHERITED;
  52. };
  53. DEF_GM( return new VideoDecoderGM; )