| 1 | /** |
| 2 | * Copyright (c) 2006-2023 LOVE Development Team |
| 3 | * |
| 4 | * This software is provided 'as-is', without any express or implied |
| 5 | * warranty. In no event will the authors be held liable for any damages |
| 6 | * arising from the use of this software. |
| 7 | * |
| 8 | * Permission is granted to anyone to use this software for any purpose, |
| 9 | * including commercial applications, and to alter it and redistribute it |
| 10 | * freely, subject to the following restrictions: |
| 11 | * |
| 12 | * 1. The origin of this software must not be misrepresented; you must not |
| 13 | * claim that you wrote the original software. If you use this software |
| 14 | * in a product, an acknowledgment in the product documentation would be |
| 15 | * appreciated but is not required. |
| 16 | * 2. Altered source versions must be plainly marked as such, and must not be |
| 17 | * misrepresented as being the original software. |
| 18 | * 3. This notice may not be removed or altered from any source distribution. |
| 19 | **/ |
| 20 | |
| 21 | #include "VideoStream.h" |
| 22 | |
| 23 | using love::thread::Lock; |
| 24 | |
| 25 | namespace love |
| 26 | { |
| 27 | namespace video |
| 28 | { |
| 29 | |
| 30 | love::Type VideoStream::type("VideoStream" , &Stream::type); |
| 31 | |
| 32 | void VideoStream::setSync(VideoStream::FrameSync *frameSync) |
| 33 | { |
| 34 | this->frameSync = frameSync; |
| 35 | } |
| 36 | |
| 37 | VideoStream::FrameSync *VideoStream::getSync() const |
| 38 | { |
| 39 | return frameSync; |
| 40 | } |
| 41 | |
| 42 | void VideoStream::play() |
| 43 | { |
| 44 | frameSync->play(); |
| 45 | } |
| 46 | |
| 47 | void VideoStream::pause() |
| 48 | { |
| 49 | frameSync->pause(); |
| 50 | } |
| 51 | |
| 52 | void VideoStream::seek(double offset) |
| 53 | { |
| 54 | frameSync->seek(offset); |
| 55 | } |
| 56 | |
| 57 | double VideoStream::tell() const |
| 58 | { |
| 59 | return frameSync->tell(); |
| 60 | } |
| 61 | |
| 62 | bool VideoStream::isPlaying() const |
| 63 | { |
| 64 | return frameSync->isPlaying(); |
| 65 | } |
| 66 | |
| 67 | VideoStream::Frame::Frame() |
| 68 | : yplane(nullptr) |
| 69 | , cbplane(nullptr) |
| 70 | , crplane(nullptr) |
| 71 | { |
| 72 | } |
| 73 | |
| 74 | VideoStream::Frame::~Frame() |
| 75 | { |
| 76 | delete[] yplane; |
| 77 | delete[] cbplane; |
| 78 | delete[] crplane; |
| 79 | } |
| 80 | |
| 81 | void VideoStream::FrameSync::copyState(const VideoStream::FrameSync *other) |
| 82 | { |
| 83 | seek(other->tell()); |
| 84 | if (other->isPlaying()) |
| 85 | play(); |
| 86 | else |
| 87 | pause(); |
| 88 | } |
| 89 | |
| 90 | double VideoStream::FrameSync::tell() const |
| 91 | { |
| 92 | return getPosition(); |
| 93 | } |
| 94 | |
| 95 | VideoStream::DeltaSync::DeltaSync() |
| 96 | : playing(false) |
| 97 | , position(0) |
| 98 | , speed(1) |
| 99 | { |
| 100 | } |
| 101 | |
| 102 | VideoStream::DeltaSync::~DeltaSync() |
| 103 | { |
| 104 | } |
| 105 | |
| 106 | double VideoStream::DeltaSync::getPosition() const |
| 107 | { |
| 108 | return position; |
| 109 | } |
| 110 | |
| 111 | void VideoStream::DeltaSync::update(double dt) |
| 112 | { |
| 113 | Lock l(mutex); |
| 114 | if (playing) |
| 115 | position += dt*speed; |
| 116 | } |
| 117 | |
| 118 | void VideoStream::DeltaSync::play() |
| 119 | { |
| 120 | playing = true; |
| 121 | } |
| 122 | |
| 123 | void VideoStream::DeltaSync::pause() |
| 124 | { |
| 125 | playing = false; |
| 126 | } |
| 127 | |
| 128 | void VideoStream::DeltaSync::seek(double time) |
| 129 | { |
| 130 | Lock l(mutex); |
| 131 | position = time; |
| 132 | } |
| 133 | |
| 134 | bool VideoStream::DeltaSync::isPlaying() const |
| 135 | { |
| 136 | return playing; |
| 137 | } |
| 138 | |
| 139 | VideoStream::SourceSync::SourceSync(love::audio::Source *source) |
| 140 | : source(source) |
| 141 | { |
| 142 | } |
| 143 | |
| 144 | double VideoStream::SourceSync::getPosition() const |
| 145 | { |
| 146 | return source->tell(love::audio::Source::UNIT_SECONDS); |
| 147 | } |
| 148 | |
| 149 | void VideoStream::SourceSync::play() |
| 150 | { |
| 151 | source->play(); |
| 152 | } |
| 153 | |
| 154 | void VideoStream::SourceSync::pause() |
| 155 | { |
| 156 | source->pause(); |
| 157 | } |
| 158 | |
| 159 | void VideoStream::SourceSync::seek(double time) |
| 160 | { |
| 161 | source->seek(time, love::audio::Source::UNIT_SECONDS); |
| 162 | } |
| 163 | |
| 164 | bool VideoStream::SourceSync::isPlaying() const |
| 165 | { |
| 166 | return source->isPlaying(); |
| 167 | } |
| 168 | |
| 169 | } // video |
| 170 | } // love |
| 171 | |