| 1 |
/* |
| 2 |
* This file is part of Bino, a 3D video player. |
| 3 |
* |
| 4 |
* Copyright (C) 2022, 2023, 2024, 2025 |
| 5 |
* Martin Lambers <[email protected]> |
| 6 |
* |
| 7 |
* This program is free software; you can redistribute it and/or modify |
| 8 |
* it under the terms of the GNU General Public License as published by |
| 9 |
* the Free Software Foundation; either version 3 of the License, or |
| 10 |
* (at your option) any later version. |
| 11 |
* |
| 12 |
* This program is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
* GNU General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU General Public License |
| 18 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 |
*/ |
| 20 |
|
| 21 |
#include <QUrl> |
| 22 |
|
| 23 |
#include "videosink.hpp" |
| 24 |
#include "log.hpp" |
| 25 |
|
| 26 |
|
| 27 |
VideoSink::VideoSink(VideoFrame* frame, VideoFrame* extFrame, bool* frameIsNew) : |
| 28 |
frameCounter(0), |
| 29 |
frame(frame), |
| 30 |
extFrame(extFrame), |
| 31 |
frameIsNew(frameIsNew), |
| 32 |
needExtFrame(false), |
| 33 |
inputMode(Input_Unknown), |
| 34 |
surroundMode(Surround_Unknown), |
| 35 |
lastFrameWasValid(false) |
| 36 |
{ |
| 37 |
connect(this, SIGNAL(videoFrameChanged(const QVideoFrame&)), this, SLOT(processNewFrame(const QVideoFrame&))); |
| 38 |
} |
| 39 |
|
| 40 |
// called whenever new media is played: |
| 41 |
void VideoSink::newPlaylistEntry(const PlaylistEntry& entry, const MetaData& metaData) |
| 42 |
{ |
| 43 |
frameCounter = 0; |
| 44 |
lastFrameWasValid = false; |
| 45 |
|
| 46 |
int vt = entry.videoTrack; |
| 47 |
if (vt < 0) |
| 48 |
vt = 0; |
| 49 |
|
| 50 |
inputMode = entry.inputMode; |
| 51 |
if (inputMode == Input_Unknown) { |
| 52 |
if (vt < metaData.inputModes.size()) |
| 53 |
inputMode = metaData.inputModes[vt]; |
| 54 |
} |
| 55 |
LOG_DEBUG("input mode for %s: %s", qPrintable(entry.url.toString()), inputModeToString(inputMode)); |
| 56 |
surroundMode = entry.surroundMode; |
| 57 |
if (surroundMode == Surround_Unknown) { |
| 58 |
if (vt < metaData.surroundModes.size()) |
| 59 |
surroundMode = metaData.surroundModes[vt]; |
| 60 |
} |
| 61 |
LOG_DEBUG("surround mode for %s: %s", qPrintable(entry.url.toString()), surroundModeToString(surroundMode)); |
| 62 |
} |
| 63 |
|
| 64 |
void VideoSink::processNewFrame(const QVideoFrame& frame) |
| 65 |
{ |
| 66 |
if (!frame.isValid() && lastFrameWasValid) { |
| 67 |
// keep showing the last frame of the current media; ignore that QtMultiMedia |
| 68 |
// with the FFmpeg backend gives us an invalid frame as soon as the media stops |
| 69 |
// (it does not do this with the GStreamer backend) |
| 70 |
LOG_DEBUG("video sink gets invalid frame and ignores it since last frame of current media was valid"); |
| 71 |
return; |
| 72 |
} |
| 73 |
if (frame.isValid()) { |
| 74 |
LOG_FIREHOSE("video sink gets a valid frame"); |
| 75 |
lastFrameWasValid = true; |
| 76 |
} |
| 77 |
|
| 78 |
bool updateExtFrame; |
| 79 |
if (inputMode == Input_Alternating_LR || inputMode == Input_Alternating_RL) { |
| 80 |
if (needExtFrame) { |
| 81 |
LOG_FIREHOSE("video sink updates extended frame for alternating mode"); |
| 82 |
updateExtFrame = true; |
| 83 |
needExtFrame = false; |
| 84 |
} else { |
| 85 |
LOG_FIREHOSE("video sink updates standard frame for alternating mode"); |
| 86 |
updateExtFrame = false; |
| 87 |
needExtFrame = true; |
| 88 |
} |
| 89 |
} else { |
| 90 |
LOG_FIREHOSE("video sink updates standard frame for non-alternating mode"); |
| 91 |
updateExtFrame = false; |
| 92 |
needExtFrame = false; |
| 93 |
} |
| 94 |
if (updateExtFrame) { |
| 95 |
this->extFrame->update(inputMode, surroundMode, frame, frameCounter == 0); |
| 96 |
} else { |
| 97 |
this->frame->update(inputMode, surroundMode, frame, frameCounter == 0); |
| 98 |
this->extFrame->invalidate(); |
| 99 |
} |
| 100 |
if (!needExtFrame) { |
| 101 |
LOG_FIREHOSE("video sink signals that new frame is complete"); |
| 102 |
*frameIsNew = true; |
| 103 |
emit newVideoFrame(); |
| 104 |
} |
| 105 |
frameCounter++; |
| 106 |
} |