Skip to content

Commit

Permalink
Provide information about frame index.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed May 23, 2021
1 parent 0c867b0 commit 802145e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
23 changes: 19 additions & 4 deletions webrtc/webrtc_video_track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,17 @@ class VideoTrack::Sink final
using PrepareFrame = not_null<Frame*>;
using PrepareState = bool;

struct FrameWithIndex {
not_null<Frame*> frame;
int index = -1;
};

[[nodiscard]] bool firstPresentHappened() const;

// Called from the main thread.
void markFrameShown();
[[nodiscard]] not_null<Frame*> frameForPaint();
[[nodiscard]] FrameWithIndex frameForPaintWithIndex();
[[nodiscard]] rpl::producer<> renderNextFrameOnMain() const;
void destroyFrameForPaint();

Expand Down Expand Up @@ -352,7 +358,12 @@ bool VideoTrack::Sink::firstPresentHappened() const {
}

not_null<VideoTrack::Frame*> VideoTrack::Sink::frameForPaint() {
return getFrame(counter() / 2);
return frameForPaintWithIndex().frame;
}

VideoTrack::Sink::FrameWithIndex VideoTrack::Sink::frameForPaintWithIndex() {
const auto index = counter() / 2;
return { .frame = getFrame(index), .index = index };
}

void VideoTrack::Sink::destroyFrameForPaint() {
Expand Down Expand Up @@ -445,14 +456,18 @@ QImage VideoTrack::frame(const FrameRequest &request) {
return frame->prepared;
}

std::pair<QImage, int> VideoTrack::frameOriginalWithRotation() const {
FrameWithInfo VideoTrack::frameWithInfo() const {
if (_disabledFrom > 0
&& (_disabledFrom + kDropFramesWhileInactive > crl::now())) {
_sink->destroyFrameForPaint();
return {};
}
const auto frame = _sink->frameForPaint();
return { frame->original, frame->rotation };
const auto data = _sink->frameForPaintWithIndex();
return {
.original = data.frame->original,
.rotation = data.frame->rotation,
.index = data.index,
};
}

QSize VideoTrack::frameSize() const {
Expand Down
8 changes: 7 additions & 1 deletion webrtc/webrtc_video_track.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ enum class VideoState {
Active,
};

struct FrameWithInfo {
QImage original;
int rotation = 0;
int index = -1;
};

class VideoTrack final {
public:
// Called from the main thread.
Expand All @@ -71,7 +77,7 @@ class VideoTrack final {

void markFrameShown();
[[nodiscard]] QImage frame(const FrameRequest &request);
[[nodiscard]] std::pair<QImage, int> frameOriginalWithRotation() const;
[[nodiscard]] FrameWithInfo frameWithInfo() const;
[[nodiscard]] QSize frameSize() const;
[[nodiscard]] rpl::producer<> renderNextFrame() const;
[[nodiscard]] std::shared_ptr<SinkInterface> sink();
Expand Down

0 comments on commit 802145e

Please sign in to comment.