2019-05-17 20:50:51 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2019 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "experimental/ffmpeg/SkVideoDecoder.h"
|
|
|
|
#include "gm/gm.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkStream.h"
|
|
|
|
|
|
|
|
class VideoDecoderGM : public skiagm::GM {
|
|
|
|
SkVideoDecoder fDecoder;
|
|
|
|
|
|
|
|
public:
|
|
|
|
VideoDecoderGM() {}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
SkString onShortName() override {
|
|
|
|
return SkString("videodecoder");
|
|
|
|
}
|
|
|
|
|
|
|
|
SkISize onISize() override {
|
|
|
|
return SkISize::Make(1024, 768);
|
|
|
|
}
|
|
|
|
|
|
|
|
void onOnceBeforeDraw() override {
|
|
|
|
if (!fDecoder.loadStream(SkStream::MakeFromFile("/skia/ice.mp4"))) {
|
|
|
|
SkDebugf("could not load movie file\n");
|
|
|
|
}
|
|
|
|
SkDebugf("duration %g\n", fDecoder.duration());
|
|
|
|
}
|
|
|
|
|
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2020-09-22 12:51:43 +00:00
|
|
|
auto* rContext = canvas->recordingContext();
|
2020-09-15 15:24:28 +00:00
|
|
|
if (!rContext) {
|
2019-05-17 20:50:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-09-15 15:24:28 +00:00
|
|
|
fDecoder.setGrContext(rContext); // context can change over time in viewer
|
2019-05-17 20:50:51 +00:00
|
|
|
|
|
|
|
double timeStamp;
|
|
|
|
auto img = fDecoder.nextImage(&timeStamp);
|
|
|
|
if (!img) {
|
|
|
|
(void)fDecoder.rewind();
|
|
|
|
img = fDecoder.nextImage(&timeStamp);
|
|
|
|
}
|
|
|
|
if (img) {
|
|
|
|
if (0) {
|
|
|
|
SkDebugf("ts %g\n", timeStamp);
|
|
|
|
}
|
|
|
|
canvas->drawImage(img, 10, 10, nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-11 20:32:53 +00:00
|
|
|
bool onAnimate(double nanos) override {
|
2019-05-17 20:50:51 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = GM;
|
2019-05-17 20:50:51 +00:00
|
|
|
};
|
|
|
|
DEF_GM( return new VideoDecoderGM; )
|
|
|
|
|