2011-07-07 08:21:25 +00:00
|
|
|
/*
|
2012-07-31 15:53:44 +00:00
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
2011-07-07 08:21:25 +00:00
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/video_coding/generic_decoder.h"
|
2017-07-05 16:45:57 -07:00
|
|
|
|
2018-11-28 16:47:49 +01:00
|
|
|
#include <stddef.h>
|
2019-07-05 19:08:33 +02:00
|
|
|
|
2017-07-06 03:06:50 -07:00
|
|
|
#include <algorithm>
|
2020-10-26 13:54:40 +01:00
|
|
|
#include <cmath>
|
2022-08-08 11:21:26 +00:00
|
|
|
#include <iterator>
|
|
|
|
|
#include <utility>
|
2017-07-06 03:06:50 -07:00
|
|
|
|
2022-08-08 11:21:26 +00:00
|
|
|
#include "absl/algorithm/container.h"
|
2022-08-04 11:52:37 +00:00
|
|
|
#include "absl/types/optional.h"
|
2018-11-28 16:47:49 +01:00
|
|
|
#include "api/video/video_timing.h"
|
2022-10-14 14:38:31 +00:00
|
|
|
#include "api/video_codecs/video_decoder.h"
|
2022-08-08 11:21:26 +00:00
|
|
|
#include "modules/include/module_common_types_public.h"
|
2018-11-28 16:47:49 +01:00
|
|
|
#include "modules/video_coding/include/video_error_codes.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/checks.h"
|
|
|
|
|
#include "rtc_base/logging.h"
|
2023-07-04 13:31:28 +02:00
|
|
|
#include "rtc_base/string_encode.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/trace_event.h"
|
|
|
|
|
#include "system_wrappers/include/clock.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
2022-08-08 11:21:26 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
constexpr size_t kDecoderFrameMemoryLength = 10;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-25 12:43:14 +01:00
|
|
|
VCMDecodedFrameCallback::VCMDecodedFrameCallback(
|
|
|
|
|
VCMTiming* timing,
|
|
|
|
|
Clock* clock,
|
2022-03-29 11:04:48 +02:00
|
|
|
const FieldTrialsView& field_trials)
|
2022-08-08 11:21:26 +00:00
|
|
|
: _clock(clock), _timing(timing) {
|
2017-06-19 07:18:55 -07:00
|
|
|
ntp_offset_ =
|
|
|
|
|
_clock->CurrentNtpInMilliseconds() - _clock->TimeInMilliseconds();
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2018-06-19 15:03:05 +02:00
|
|
|
VCMDecodedFrameCallback::~VCMDecodedFrameCallback() {}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2011-10-10 14:17:46 +00:00
|
|
|
void VCMDecodedFrameCallback::SetUserReceiveCallback(
|
2015-12-21 04:12:39 -08:00
|
|
|
VCMReceiveCallback* receiveCallback) {
|
2019-04-08 15:20:44 +02:00
|
|
|
RTC_DCHECK(construction_thread_.IsCurrent());
|
2017-03-14 04:16:20 -07:00
|
|
|
RTC_DCHECK((!_receiveCallback && receiveCallback) ||
|
|
|
|
|
(_receiveCallback && !receiveCallback));
|
2015-12-21 04:12:39 -08:00
|
|
|
_receiveCallback = receiveCallback;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2015-12-21 04:12:39 -08:00
|
|
|
VCMReceiveCallback* VCMDecodedFrameCallback::UserReceiveCallback() {
|
2017-03-14 04:16:20 -07:00
|
|
|
// Called on the decode thread via VCMCodecDataBase::GetDecoder.
|
|
|
|
|
// The callback must always have been set before this happens.
|
|
|
|
|
RTC_DCHECK(_receiveCallback);
|
2015-12-21 04:12:39 -08:00
|
|
|
return _receiveCallback;
|
2013-08-12 14:20:49 +00:00
|
|
|
}
|
|
|
|
|
|
2015-05-29 17:21:40 -07:00
|
|
|
int32_t VCMDecodedFrameCallback::Decoded(VideoFrame& decodedImage) {
|
2020-05-05 15:35:45 +02:00
|
|
|
// This function may be called on the decode TaskQueue, but may also be called
|
|
|
|
|
// on an OS provided queue such as on iOS (see e.g. b/153465112).
|
2015-11-10 14:00:27 +01:00
|
|
|
return Decoded(decodedImage, -1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t VCMDecodedFrameCallback::Decoded(VideoFrame& decodedImage,
|
|
|
|
|
int64_t decode_time_ms) {
|
Reland of Add QP sum stats for received streams. (patchset #2 id:300001 of https://codereview.webrtc.org/2680893002/ )
Reason for revert:
Fix the problem.
Original issue's description:
> Revert of Add QP sum stats for received streams. (patchset #10 id:180001 of https://codereview.webrtc.org/2649133005/ )
>
> Reason for revert:
> Breaks downstream build.
>
> Original issue's description:
> > Add QP sum stats for received streams.
> >
> > This is not implemented yet in any of the decoders.
> >
> > BUG=webrtc:6541
> >
> > Review-Url: https://codereview.webrtc.org/2649133005
> > Cr-Commit-Position: refs/heads/master@{#16475}
> > Committed: https://chromium.googlesource.com/external/webrtc/+/ff0e72fd165facac27f0313aa178648782e63bc4
>
> TBR=hta@webrtc.org,hbos@webrtc.org,sprang@webrtc.org,magjed@webrtc.org,stefan@webrtc.org,sakal@webrtc.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=webrtc:6541
>
> Review-Url: https://codereview.webrtc.org/2680893002 .
> Cr-Commit-Position: refs/heads/master@{#16480}
> Committed: https://chromium.googlesource.com/external/webrtc/+/69fb2cca4d54f3df7ceddcd1c3e9b0ad80fa849b
TBR=hta@webrtc.org,hbos@webrtc.org,sprang@webrtc.org,magjed@webrtc.org,stefan@webrtc.org,skvlad@webrtc.org
BUG=webrtc:6541
Review-Url: https://codereview.webrtc.org/2681663005
Cr-Commit-Position: refs/heads/master@{#16511}
2017-02-09 04:53:45 -08:00
|
|
|
Decoded(decodedImage,
|
2018-06-18 10:48:16 +02:00
|
|
|
decode_time_ms >= 0 ? absl::optional<int32_t>(decode_time_ms)
|
|
|
|
|
: absl::nullopt,
|
|
|
|
|
absl::nullopt);
|
Reland of Add QP sum stats for received streams. (patchset #2 id:300001 of https://codereview.webrtc.org/2680893002/ )
Reason for revert:
Fix the problem.
Original issue's description:
> Revert of Add QP sum stats for received streams. (patchset #10 id:180001 of https://codereview.webrtc.org/2649133005/ )
>
> Reason for revert:
> Breaks downstream build.
>
> Original issue's description:
> > Add QP sum stats for received streams.
> >
> > This is not implemented yet in any of the decoders.
> >
> > BUG=webrtc:6541
> >
> > Review-Url: https://codereview.webrtc.org/2649133005
> > Cr-Commit-Position: refs/heads/master@{#16475}
> > Committed: https://chromium.googlesource.com/external/webrtc/+/ff0e72fd165facac27f0313aa178648782e63bc4
>
> TBR=hta@webrtc.org,hbos@webrtc.org,sprang@webrtc.org,magjed@webrtc.org,stefan@webrtc.org,sakal@webrtc.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=webrtc:6541
>
> Review-Url: https://codereview.webrtc.org/2680893002 .
> Cr-Commit-Position: refs/heads/master@{#16480}
> Committed: https://chromium.googlesource.com/external/webrtc/+/69fb2cca4d54f3df7ceddcd1c3e9b0ad80fa849b
TBR=hta@webrtc.org,hbos@webrtc.org,sprang@webrtc.org,magjed@webrtc.org,stefan@webrtc.org,skvlad@webrtc.org
BUG=webrtc:6541
Review-Url: https://codereview.webrtc.org/2681663005
Cr-Commit-Position: refs/heads/master@{#16511}
2017-02-09 04:53:45 -08:00
|
|
|
return WEBRTC_VIDEO_CODEC_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-08 11:21:26 +00:00
|
|
|
std::pair<absl::optional<FrameInfo>, size_t>
|
|
|
|
|
VCMDecodedFrameCallback::FindFrameInfo(uint32_t rtp_timestamp) {
|
|
|
|
|
absl::optional<FrameInfo> frame_info;
|
|
|
|
|
|
|
|
|
|
auto it = absl::c_find_if(frame_infos_, [rtp_timestamp](const auto& entry) {
|
|
|
|
|
return entry.rtp_timestamp == rtp_timestamp ||
|
|
|
|
|
IsNewerTimestamp(entry.rtp_timestamp, rtp_timestamp);
|
|
|
|
|
});
|
|
|
|
|
size_t dropped_frames = std::distance(frame_infos_.begin(), it);
|
|
|
|
|
|
|
|
|
|
if (it != frame_infos_.end() && it->rtp_timestamp == rtp_timestamp) {
|
|
|
|
|
// Frame was found and should also be removed from the queue.
|
|
|
|
|
frame_info = std::move(*it);
|
|
|
|
|
++it;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
frame_infos_.erase(frame_infos_.begin(), it);
|
|
|
|
|
return std::make_pair(std::move(frame_info), dropped_frames);
|
|
|
|
|
}
|
|
|
|
|
|
Reland of Add QP sum stats for received streams. (patchset #2 id:300001 of https://codereview.webrtc.org/2680893002/ )
Reason for revert:
Fix the problem.
Original issue's description:
> Revert of Add QP sum stats for received streams. (patchset #10 id:180001 of https://codereview.webrtc.org/2649133005/ )
>
> Reason for revert:
> Breaks downstream build.
>
> Original issue's description:
> > Add QP sum stats for received streams.
> >
> > This is not implemented yet in any of the decoders.
> >
> > BUG=webrtc:6541
> >
> > Review-Url: https://codereview.webrtc.org/2649133005
> > Cr-Commit-Position: refs/heads/master@{#16475}
> > Committed: https://chromium.googlesource.com/external/webrtc/+/ff0e72fd165facac27f0313aa178648782e63bc4
>
> TBR=hta@webrtc.org,hbos@webrtc.org,sprang@webrtc.org,magjed@webrtc.org,stefan@webrtc.org,sakal@webrtc.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=webrtc:6541
>
> Review-Url: https://codereview.webrtc.org/2680893002 .
> Cr-Commit-Position: refs/heads/master@{#16480}
> Committed: https://chromium.googlesource.com/external/webrtc/+/69fb2cca4d54f3df7ceddcd1c3e9b0ad80fa849b
TBR=hta@webrtc.org,hbos@webrtc.org,sprang@webrtc.org,magjed@webrtc.org,stefan@webrtc.org,skvlad@webrtc.org
BUG=webrtc:6541
Review-Url: https://codereview.webrtc.org/2681663005
Cr-Commit-Position: refs/heads/master@{#16511}
2017-02-09 04:53:45 -08:00
|
|
|
void VCMDecodedFrameCallback::Decoded(VideoFrame& decodedImage,
|
2018-06-18 10:48:16 +02:00
|
|
|
absl::optional<int32_t> decode_time_ms,
|
|
|
|
|
absl::optional<uint8_t> qp) {
|
2017-03-14 04:16:20 -07:00
|
|
|
RTC_DCHECK(_receiveCallback) << "Callback must not be null at this point";
|
2015-12-21 04:12:39 -08:00
|
|
|
TRACE_EVENT_INSTANT1("webrtc", "VCMDecodedFrameCallback::Decoded",
|
|
|
|
|
"timestamp", decodedImage.timestamp());
|
|
|
|
|
// TODO(holmer): We should improve this so that we can handle multiple
|
|
|
|
|
// callbacks from one call to Decode().
|
2022-08-08 11:21:26 +00:00
|
|
|
absl::optional<FrameInfo> frame_info;
|
2020-10-26 13:54:40 +01:00
|
|
|
int timestamp_map_size = 0;
|
2021-04-09 16:03:22 +02:00
|
|
|
int dropped_frames = 0;
|
2018-02-21 19:38:59 +00:00
|
|
|
{
|
2020-07-07 12:17:12 +02:00
|
|
|
MutexLock lock(&lock_);
|
2022-08-08 11:21:26 +00:00
|
|
|
std::tie(frame_info, dropped_frames) =
|
|
|
|
|
FindFrameInfo(decodedImage.timestamp());
|
|
|
|
|
timestamp_map_size = frame_infos_.size();
|
2021-04-09 16:03:22 +02:00
|
|
|
}
|
|
|
|
|
if (dropped_frames > 0) {
|
|
|
|
|
_receiveCallback->OnDroppedFrames(dropped_frames);
|
2018-02-21 19:38:59 +00:00
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2022-08-08 11:21:26 +00:00
|
|
|
if (!frame_info) {
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_LOG(LS_WARNING) << "Too many frames backed up in the decoder, dropping "
|
2021-06-17 10:50:56 +02:00
|
|
|
"frame with timestamp "
|
|
|
|
|
<< decodedImage.timestamp();
|
Reland of Add QP sum stats for received streams. (patchset #2 id:300001 of https://codereview.webrtc.org/2680893002/ )
Reason for revert:
Fix the problem.
Original issue's description:
> Revert of Add QP sum stats for received streams. (patchset #10 id:180001 of https://codereview.webrtc.org/2649133005/ )
>
> Reason for revert:
> Breaks downstream build.
>
> Original issue's description:
> > Add QP sum stats for received streams.
> >
> > This is not implemented yet in any of the decoders.
> >
> > BUG=webrtc:6541
> >
> > Review-Url: https://codereview.webrtc.org/2649133005
> > Cr-Commit-Position: refs/heads/master@{#16475}
> > Committed: https://chromium.googlesource.com/external/webrtc/+/ff0e72fd165facac27f0313aa178648782e63bc4
>
> TBR=hta@webrtc.org,hbos@webrtc.org,sprang@webrtc.org,magjed@webrtc.org,stefan@webrtc.org,sakal@webrtc.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=webrtc:6541
>
> Review-Url: https://codereview.webrtc.org/2680893002 .
> Cr-Commit-Position: refs/heads/master@{#16480}
> Committed: https://chromium.googlesource.com/external/webrtc/+/69fb2cca4d54f3df7ceddcd1c3e9b0ad80fa849b
TBR=hta@webrtc.org,hbos@webrtc.org,sprang@webrtc.org,magjed@webrtc.org,stefan@webrtc.org,skvlad@webrtc.org
BUG=webrtc:6541
Review-Url: https://codereview.webrtc.org/2681663005
Cr-Commit-Position: refs/heads/master@{#16511}
2017-02-09 04:53:45 -08:00
|
|
|
return;
|
2015-12-21 04:12:39 -08:00
|
|
|
}
|
|
|
|
|
|
2022-08-08 11:21:26 +00:00
|
|
|
decodedImage.set_ntp_time_ms(frame_info->ntp_time_ms);
|
|
|
|
|
decodedImage.set_packet_infos(frame_info->packet_infos);
|
|
|
|
|
decodedImage.set_rotation(frame_info->rotation);
|
2022-06-15 12:27:23 +02:00
|
|
|
VideoFrame::RenderParameters render_parameters = _timing->RenderParameters();
|
|
|
|
|
if (render_parameters.max_composition_delay_in_frames) {
|
2022-04-26 11:10:21 +02:00
|
|
|
// Subtract frames that are in flight.
|
2022-06-15 12:27:23 +02:00
|
|
|
render_parameters.max_composition_delay_in_frames =
|
|
|
|
|
std::max(0, *render_parameters.max_composition_delay_in_frames -
|
|
|
|
|
timestamp_map_size);
|
2020-10-26 13:54:40 +01:00
|
|
|
}
|
2022-06-15 12:27:23 +02:00
|
|
|
decodedImage.set_render_parameters(render_parameters);
|
2020-10-26 13:54:40 +01:00
|
|
|
|
2022-08-08 11:21:26 +00:00
|
|
|
RTC_DCHECK(frame_info->decode_start);
|
2020-10-02 14:46:14 +02:00
|
|
|
const Timestamp now = _clock->CurrentTime();
|
|
|
|
|
const TimeDelta decode_time = decode_time_ms
|
|
|
|
|
? TimeDelta::Millis(*decode_time_ms)
|
2022-08-08 11:21:26 +00:00
|
|
|
: now - *frame_info->decode_start;
|
2022-03-02 15:13:55 +01:00
|
|
|
_timing->StopDecodeTimer(decode_time, now);
|
2020-10-02 14:46:14 +02:00
|
|
|
decodedImage.set_processing_time(
|
2022-08-08 11:21:26 +00:00
|
|
|
{*frame_info->decode_start, *frame_info->decode_start + decode_time});
|
2015-12-21 04:12:39 -08:00
|
|
|
|
2017-06-19 07:18:55 -07:00
|
|
|
// Report timing information.
|
2018-12-07 03:45:19 -08:00
|
|
|
TimingFrameInfo timing_frame_info;
|
2022-08-08 11:21:26 +00:00
|
|
|
if (frame_info->timing.flags != VideoSendTiming::kInvalid) {
|
2017-07-06 03:06:50 -07:00
|
|
|
int64_t capture_time_ms = decodedImage.ntp_time_ms() - ntp_offset_;
|
2017-06-19 07:18:55 -07:00
|
|
|
// Convert remote timestamps to local time from ntp timestamps.
|
2022-08-08 11:21:26 +00:00
|
|
|
frame_info->timing.encode_start_ms -= ntp_offset_;
|
|
|
|
|
frame_info->timing.encode_finish_ms -= ntp_offset_;
|
|
|
|
|
frame_info->timing.packetization_finish_ms -= ntp_offset_;
|
|
|
|
|
frame_info->timing.pacer_exit_ms -= ntp_offset_;
|
|
|
|
|
frame_info->timing.network_timestamp_ms -= ntp_offset_;
|
|
|
|
|
frame_info->timing.network2_timestamp_ms -= ntp_offset_;
|
2017-07-06 03:06:50 -07:00
|
|
|
|
|
|
|
|
int64_t sender_delta_ms = 0;
|
|
|
|
|
if (decodedImage.ntp_time_ms() < 0) {
|
|
|
|
|
// Sender clock is not estimated yet. Make sure that sender times are all
|
|
|
|
|
// negative to indicate that. Yet they still should be relatively correct.
|
|
|
|
|
sender_delta_ms =
|
2022-08-08 11:21:26 +00:00
|
|
|
std::max({capture_time_ms, frame_info->timing.encode_start_ms,
|
|
|
|
|
frame_info->timing.encode_finish_ms,
|
|
|
|
|
frame_info->timing.packetization_finish_ms,
|
|
|
|
|
frame_info->timing.pacer_exit_ms,
|
|
|
|
|
frame_info->timing.network_timestamp_ms,
|
|
|
|
|
frame_info->timing.network2_timestamp_ms}) +
|
2017-07-06 03:06:50 -07:00
|
|
|
1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
timing_frame_info.capture_time_ms = capture_time_ms - sender_delta_ms;
|
|
|
|
|
timing_frame_info.encode_start_ms =
|
2022-08-08 11:21:26 +00:00
|
|
|
frame_info->timing.encode_start_ms - sender_delta_ms;
|
2017-07-06 03:06:50 -07:00
|
|
|
timing_frame_info.encode_finish_ms =
|
2022-08-08 11:21:26 +00:00
|
|
|
frame_info->timing.encode_finish_ms - sender_delta_ms;
|
2017-07-06 03:06:50 -07:00
|
|
|
timing_frame_info.packetization_finish_ms =
|
2022-08-08 11:21:26 +00:00
|
|
|
frame_info->timing.packetization_finish_ms - sender_delta_ms;
|
2017-07-06 03:06:50 -07:00
|
|
|
timing_frame_info.pacer_exit_ms =
|
2022-08-08 11:21:26 +00:00
|
|
|
frame_info->timing.pacer_exit_ms - sender_delta_ms;
|
2017-07-06 03:06:50 -07:00
|
|
|
timing_frame_info.network_timestamp_ms =
|
2022-08-08 11:21:26 +00:00
|
|
|
frame_info->timing.network_timestamp_ms - sender_delta_ms;
|
2017-07-06 03:06:50 -07:00
|
|
|
timing_frame_info.network2_timestamp_ms =
|
2022-08-08 11:21:26 +00:00
|
|
|
frame_info->timing.network2_timestamp_ms - sender_delta_ms;
|
2017-06-19 07:18:55 -07:00
|
|
|
}
|
|
|
|
|
|
2022-08-08 11:21:26 +00:00
|
|
|
timing_frame_info.flags = frame_info->timing.flags;
|
|
|
|
|
timing_frame_info.decode_start_ms = frame_info->decode_start->ms();
|
2020-01-16 14:09:33 +01:00
|
|
|
timing_frame_info.decode_finish_ms = now.ms();
|
2022-08-04 11:52:37 +00:00
|
|
|
timing_frame_info.render_time_ms =
|
2022-08-08 11:21:26 +00:00
|
|
|
frame_info->render_time ? frame_info->render_time->ms() : -1;
|
2018-12-07 03:45:19 -08:00
|
|
|
timing_frame_info.rtp_timestamp = decodedImage.timestamp();
|
2022-08-08 11:21:26 +00:00
|
|
|
timing_frame_info.receive_start_ms = frame_info->timing.receive_start_ms;
|
|
|
|
|
timing_frame_info.receive_finish_ms = frame_info->timing.receive_finish_ms;
|
2018-12-07 03:45:19 -08:00
|
|
|
_timing->SetTimingFrameInfo(timing_frame_info);
|
|
|
|
|
|
2022-08-04 11:52:37 +00:00
|
|
|
decodedImage.set_timestamp_us(
|
2022-08-08 11:21:26 +00:00
|
|
|
frame_info->render_time ? frame_info->render_time->us() : -1);
|
2022-06-17 07:34:23 +02:00
|
|
|
_receiveCallback->FrameToRender(decodedImage, qp, decode_time,
|
2023-08-14 15:16:05 +00:00
|
|
|
frame_info->content_type);
|
2015-12-21 04:12:39 -08:00
|
|
|
}
|
|
|
|
|
|
2022-10-14 14:38:31 +00:00
|
|
|
void VCMDecodedFrameCallback::OnDecoderInfoChanged(
|
|
|
|
|
const VideoDecoder::DecoderInfo& decoder_info) {
|
|
|
|
|
_receiveCallback->OnDecoderInfoChanged(decoder_info);
|
2015-12-18 16:01:11 +01:00
|
|
|
}
|
|
|
|
|
|
2022-08-08 11:21:26 +00:00
|
|
|
void VCMDecodedFrameCallback::Map(FrameInfo frameInfo) {
|
2021-04-09 16:03:22 +02:00
|
|
|
int dropped_frames = 0;
|
|
|
|
|
{
|
|
|
|
|
MutexLock lock(&lock_);
|
2022-08-08 11:21:26 +00:00
|
|
|
int initial_size = frame_infos_.size();
|
|
|
|
|
if (initial_size == kDecoderFrameMemoryLength) {
|
|
|
|
|
frame_infos_.pop_front();
|
|
|
|
|
dropped_frames = 1;
|
|
|
|
|
}
|
|
|
|
|
frame_infos_.push_back(std::move(frameInfo));
|
2021-08-09 13:02:57 +02:00
|
|
|
// If no frame is dropped, the new size should be `initial_size` + 1
|
2021-04-09 16:03:22 +02:00
|
|
|
}
|
|
|
|
|
if (dropped_frames > 0) {
|
|
|
|
|
_receiveCallback->OnDroppedFrames(dropped_frames);
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2021-04-09 16:03:22 +02:00
|
|
|
void VCMDecodedFrameCallback::ClearTimestampMap() {
|
|
|
|
|
int dropped_frames = 0;
|
|
|
|
|
{
|
|
|
|
|
MutexLock lock(&lock_);
|
2022-08-08 11:21:26 +00:00
|
|
|
dropped_frames = frame_infos_.size();
|
|
|
|
|
frame_infos_.clear();
|
2021-04-09 16:03:22 +02:00
|
|
|
}
|
|
|
|
|
if (dropped_frames > 0) {
|
|
|
|
|
_receiveCallback->OnDroppedFrames(dropped_frames);
|
2018-02-21 19:38:59 +00:00
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2021-08-06 12:30:02 +02:00
|
|
|
VCMGenericDecoder::VCMGenericDecoder(VideoDecoder* decoder)
|
2015-12-01 17:20:01 +01:00
|
|
|
: _callback(NULL),
|
2017-07-05 16:45:57 -07:00
|
|
|
decoder_(decoder),
|
|
|
|
|
_last_keyframe_content_type(VideoContentType::UNSPECIFIED) {
|
|
|
|
|
RTC_DCHECK(decoder_);
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2017-07-05 16:45:57 -07:00
|
|
|
VCMGenericDecoder::~VCMGenericDecoder() {
|
|
|
|
|
decoder_->Release();
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2021-08-13 16:50:37 +02:00
|
|
|
bool VCMGenericDecoder::Configure(const VideoDecoder::Settings& settings) {
|
|
|
|
|
TRACE_EVENT0("webrtc", "VCMGenericDecoder::Configure");
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2021-08-13 16:50:37 +02:00
|
|
|
bool ok = decoder_->Configure(settings);
|
2021-01-13 21:49:59 +01:00
|
|
|
decoder_info_ = decoder_->GetDecoderInfo();
|
|
|
|
|
RTC_LOG(LS_INFO) << "Decoder implementation: " << decoder_info_.ToString();
|
|
|
|
|
if (_callback) {
|
2022-10-14 14:38:31 +00:00
|
|
|
_callback->OnDecoderInfoChanged(decoder_info_);
|
2021-01-13 21:49:59 +01:00
|
|
|
}
|
2021-08-13 16:50:37 +02:00
|
|
|
return ok;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2020-01-16 14:09:33 +01:00
|
|
|
int32_t VCMGenericDecoder::Decode(const VCMEncodedFrame& frame, Timestamp now) {
|
2018-06-19 15:03:05 +02:00
|
|
|
TRACE_EVENT1("webrtc", "VCMGenericDecoder::Decode", "timestamp",
|
2018-08-16 10:24:12 +02:00
|
|
|
frame.Timestamp());
|
2022-08-08 11:21:26 +00:00
|
|
|
FrameInfo frame_info;
|
|
|
|
|
frame_info.rtp_timestamp = frame.Timestamp();
|
2022-08-04 11:52:37 +00:00
|
|
|
frame_info.decode_start = now;
|
|
|
|
|
frame_info.render_time =
|
|
|
|
|
frame.RenderTimeMs() >= 0
|
|
|
|
|
? absl::make_optional(Timestamp::Millis(frame.RenderTimeMs()))
|
|
|
|
|
: absl::nullopt;
|
2021-03-03 14:39:44 +01:00
|
|
|
frame_info.rotation = frame.rotation();
|
|
|
|
|
frame_info.timing = frame.video_timing();
|
|
|
|
|
frame_info.ntp_time_ms = frame.EncodedImage().ntp_time_ms_;
|
|
|
|
|
frame_info.packet_infos = frame.PacketInfos();
|
2019-05-13 16:13:36 +02:00
|
|
|
|
2018-06-19 15:03:05 +02:00
|
|
|
// Set correctly only for key frames. Thus, use latest key frame
|
|
|
|
|
// content type. If the corresponding key frame was lost, decode will fail
|
|
|
|
|
// and content type will be ignored.
|
2019-03-21 15:43:58 +01:00
|
|
|
if (frame.FrameType() == VideoFrameType::kVideoFrameKey) {
|
2021-03-03 14:39:44 +01:00
|
|
|
frame_info.content_type = frame.contentType();
|
2018-06-19 15:03:05 +02:00
|
|
|
_last_keyframe_content_type = frame.contentType();
|
|
|
|
|
} else {
|
2021-03-03 14:39:44 +01:00
|
|
|
frame_info.content_type = _last_keyframe_content_type;
|
2018-06-19 15:03:05 +02:00
|
|
|
}
|
2022-08-08 11:21:26 +00:00
|
|
|
_callback->Map(std::move(frame_info));
|
2018-06-19 15:03:05 +02:00
|
|
|
|
|
|
|
|
int32_t ret = decoder_->Decode(frame.EncodedImage(), frame.MissingFrame(),
|
2019-03-25 09:11:40 +01:00
|
|
|
frame.RenderTimeMs());
|
2021-01-13 21:49:59 +01:00
|
|
|
VideoDecoder::DecoderInfo decoder_info = decoder_->GetDecoderInfo();
|
|
|
|
|
if (decoder_info != decoder_info_) {
|
2020-05-15 12:24:29 +02:00
|
|
|
RTC_LOG(LS_INFO) << "Changed decoder implementation to: "
|
2021-01-13 21:49:59 +01:00
|
|
|
<< decoder_info.ToString();
|
2021-03-12 16:36:49 +01:00
|
|
|
decoder_info_ = decoder_info;
|
2022-10-14 14:38:31 +00:00
|
|
|
if (decoder_info.implementation_name.empty()) {
|
|
|
|
|
decoder_info.implementation_name = "unknown";
|
|
|
|
|
}
|
|
|
|
|
_callback->OnDecoderInfoChanged(std::move(decoder_info));
|
2020-05-15 12:24:29 +02:00
|
|
|
}
|
2018-06-19 15:03:05 +02:00
|
|
|
if (ret < WEBRTC_VIDEO_CODEC_OK) {
|
2023-07-04 13:31:28 +02:00
|
|
|
const absl::optional<uint32_t> ssrc =
|
|
|
|
|
!frame_info.packet_infos.empty()
|
|
|
|
|
? absl::make_optional(frame_info.packet_infos[0].ssrc())
|
|
|
|
|
: absl::nullopt;
|
2018-06-19 15:03:05 +02:00
|
|
|
RTC_LOG(LS_WARNING) << "Failed to decode frame with timestamp "
|
2023-07-04 13:31:28 +02:00
|
|
|
<< frame.Timestamp() << ", ssrc "
|
|
|
|
|
<< (ssrc ? rtc::ToString(*ssrc) : "<not set>")
|
|
|
|
|
<< ", error code: " << ret;
|
2021-04-09 16:03:22 +02:00
|
|
|
_callback->ClearTimestampMap();
|
2018-12-04 11:01:26 +01:00
|
|
|
} else if (ret == WEBRTC_VIDEO_CODEC_NO_OUTPUT) {
|
2021-04-09 16:03:22 +02:00
|
|
|
// No output.
|
|
|
|
|
_callback->ClearTimestampMap();
|
2018-06-19 15:03:05 +02:00
|
|
|
}
|
|
|
|
|
return ret;
|
Revert of Deliver video frames on Android, on the decode thread. (patchset #7 id:120001 of https://codereview.webrtc.org/2764573002/ )
Reason for revert:
Breaks Chrome FYI Android bots.
See:
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus9%29/builds/20418
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus6%29/builds/14724
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus5%29/builds/20133
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28K%20Nexus5%29/builds/15111
Original issue's description:
> Deliver video frames on Android, on the decode thread.
>
> VideoCoding
> * Adding a method for polling for frames on Android only until the capture implementation takes care of this (longer term plan).
>
> CodecDatabase
> * Add an accessor for the current decoder
> * Use std::unique_ptr<> for ownership.
> * Remove "Release()" and "ReleaseDecoder()". Instead just delete.
> * Remove |friend| relationship between CodecDatabase and VCMGenericDecoder.
>
> VCMDecodedFrameCallback
> * DCHECKs for thread correctness.
> * Remove |lock_| now that a threading model has been established and verified.
>
> VCMGenericDecoder
> * All methods now have thread checks.
> * Variable access associated with thread checkers.
>
> VideoReceiver
> * Added two notification methods, DecoderThreadStarting() and DecoderThreadStopped()
> * Allows us to establish a period when the decoder thread is not running and it is safe to modify variables such as callbacks, that are only read when the decoder thread is running.
> * Allows us to DCHECK thread guarantees.
> * Allows synchronizing callbacks from the module process thread and have them only active while the decoder thread is running.
> * The above, allows us to establish two modes for the thread, single-threaded-mutable and multi-threaded-const.
> * Using that knowledge, we can remove |receive_crit_| as well as locking for a number of member variables.
>
> MediaCodecVideoDecoder
> * Removed frame polling code from this class, since this is now done from the root thread function in VideoReceiveStream.
>
> VideoReceiveStream
> * On Android: Polls for decoded frames every 10ms (same interval as previously in MediaCodecVideoDecoder)
> * [Un]Registers the |video_receiver_| with the module thread only around the time the decoder thread is started/stopped.
> * Notifies the receiver of start/stop events of the decoder thread.
> * Changed the decoder thread to use the new PlatformThread callback type.
>
> BUG=webrtc:7361, 695438
>
> Review-Url: https://codereview.webrtc.org/2764573002
> Cr-Commit-Position: refs/heads/master@{#17527}
> Committed: https://chromium.googlesource.com/external/webrtc/+/e3aa88bbd5accadec73fa7e38584dfbf6aabe8a9
TBR=sakal@webrtc.org,mflodman@webrtc.org,stefan@webrtc.org,tommi@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:7361, 695438
Review-Url: https://codereview.webrtc.org/2792033003
Cr-Commit-Position: refs/heads/master@{#17530}
2017-04-04 07:16:21 -07:00
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-12-01 17:20:01 +01:00
|
|
|
int32_t VCMGenericDecoder::RegisterDecodeCompleteCallback(
|
|
|
|
|
VCMDecodedFrameCallback* callback) {
|
|
|
|
|
_callback = callback;
|
2021-01-13 21:49:59 +01:00
|
|
|
int32_t ret = decoder_->RegisterDecodeCompleteCallback(callback);
|
|
|
|
|
if (callback && !decoder_info_.implementation_name.empty()) {
|
2022-10-14 14:38:31 +00:00
|
|
|
callback->OnDecoderInfoChanged(decoder_info_);
|
2021-01-13 21:49:59 +01:00
|
|
|
}
|
|
|
|
|
return ret;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2015-12-21 04:12:39 -08:00
|
|
|
} // namespace webrtc
|