Flutter Engine
The Flutter Engine
AudioLayer.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2020 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
14#include "src/utils/SkJSON.h"
15
16#include <utility>
17
18namespace skottie::internal {
19
20namespace {
21
22class ForwardingPlaybackController final : public Animator {
23public:
24 ForwardingPlaybackController(sk_sp<skresources::ExternalTrackAsset> track,
25 float in_point,
26 float out_point,
27 float fps )
28 : fTrack(std::move(track))
29 , fInPoint(in_point)
30 , fOutPoint(out_point)
31 , fFps(fps) {}
32
33private:
34 StateChanged onSeek(float t) override {
35 // Adjust t relative to the track time (s).
36 if (t < fInPoint || t > fOutPoint) {
37 t = -1;
38 } else {
39 t = (t - fInPoint) / fFps;
40 }
41
42 fTrack->seek(t);
43
44 // does not interact with the render tree.
45 return false;
46 }
47
49 const float fInPoint,
50 fOutPoint,
51 fFps;
52};
53
54} // namespace
55
56sk_sp<sksg::RenderNode> AnimationBuilder::attachAudioLayer(const skjson::ObjectValue& jlayer,
57 LayerInfo* layer_info) const {
58 const ScopedAssetRef audio_asset(this, jlayer);
59
60 if (audio_asset) {
61 const auto& jaudio = *audio_asset;
62 const skjson::StringValue* name = jaudio["p"];
63 const skjson::StringValue* path = jaudio["u"];
64 const skjson::StringValue* id = jaudio["id"];
65
66 if (name && path && id) {
67 auto track = fResourceProvider->loadAudioAsset(path->begin(),
68 name->begin(),
69 id ->begin());
70 if (track) {
71 fCurrentAnimatorScope->push_back(
72 sk_make_sp<ForwardingPlaybackController>(std::move(track),
73 layer_info->fInPoint,
74 layer_info->fOutPoint,
75 fFrameRate));
76 } else {
77 this->log(Logger::Level::kWarning, nullptr,
78 "Could not load audio asset '%s'.", name->begin());
79 }
80 }
81 }
82
83 // no render node, playback is controlled from the Animator tree.
84 return nullptr;
85}
86
87} // namespace skottie::internal
const char * begin() const
Definition: SkJSON.h:315
void log(Logger::Level, const skjson::Value *, const char fmt[],...) const SK_PRINTF_LIKE(4
Definition: Skottie.cpp:71
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
Definition: ref_ptr.h:256
const uintptr_t id