Skip to content

Commit

Permalink
[media] Support progressive playback
Browse files Browse the repository at this point in the history
This PR brings the progressive demuxer from Cobalt C25 to support progressive videos.

b/322033277
  • Loading branch information
borongc committed Nov 22, 2024
1 parent e103384 commit 2c6a160
Show file tree
Hide file tree
Showing 27 changed files with 7,896 additions and 0 deletions.
1 change: 1 addition & 0 deletions media/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ test("media_unittests") {
# TODO(cobalt, b/379934658): add starboard_renderer_test.
# TODO(cobalt, b/379936173): enable starboard_utils_test.
# TODO(cobalt, b/379934533): enable bidirectional_fit_reuse_allocator_test.
# TODO(cobalt, b/380335617): enable progressive demuxer tests.
# deps += ["//media/starboard:unit_tests"]
}

Expand Down
1 change: 1 addition & 0 deletions media/base/decoder_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ class MEDIA_EXPORT DecoderBuffer
// If there's no data in this buffer, it represents end of stream.
#if BUILDFLAG(USE_STARBOARD_MEDIA)
bool end_of_stream() const { return !data_; }
void shrink_to(size_t size) { DCHECK_LE(size, size_); size_ = size; }
#else // BUILDFLAG(USE_STARBOARD_MEDIA)
bool end_of_stream() const {
return !read_only_mapping_.IsValid() && !writable_mapping_.IsValid() &&
Expand Down
29 changes: 29 additions & 0 deletions media/filters/demuxer_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
#include "media/filters/manifest_demuxer.h"
#endif // BUILDFLAG(ENABLE_HLS_DEMUXER)

#if BUILDFLAG(ENABLE_FFMPEG)
#elif BUILDFLAG(USE_STARBOARD_MEDIA)
#include "media/starboard/progressive/demuxer_extension_wrapper.h"
#include "media/starboard/progressive/progressive_demuxer.h"
#endif // BUILDFLAG(USE_STARBOARD_MEDIA)

namespace media {

namespace {
Expand Down Expand Up @@ -409,6 +415,8 @@ PipelineStatus DemuxerManager::CreateDemuxer(
} else if (!load_media_source) {
#if BUILDFLAG(ENABLE_FFMPEG)
SetDemuxer(CreateFFmpegDemuxer());
#elif BUILDFLAG(USE_STARBOARD_MEDIA)
SetDemuxer(CreateProgressiveDemuxer());
#else
return DEMUXER_ERROR_COULD_NOT_OPEN;
#endif
Expand Down Expand Up @@ -576,6 +584,27 @@ std::unique_ptr<Demuxer> DemuxerManager::CreateFFmpegDemuxer() {
weak_factory_.GetWeakPtr())),
media_log_.get(), IsLocalFile(loaded_url_));
}
#elif BUILDFLAG(USE_STARBOARD_MEDIA)
std::unique_ptr<Demuxer> DemuxerManager::CreateDemuxerExtensionWrapper() {
DCHECK(data_source_);
return DemuxerExtensionWrapper::Create(
data_source_.get(), media_task_runner_);
}
std::unique_ptr<Demuxer> DemuxerManager::CreateProgressiveDemuxer() {
DCHECK(data_source_);
std::unique_ptr<Demuxer> progressive_demuxer_ = CreateDemuxerExtensionWrapper();
if (progressive_demuxer_) {
LOG(INFO) << "Using DemuxerExtensionWrapper.";
return progressive_demuxer_;
} else {
// Either the demuxer Cobalt extension was not provided, or it failed to
// create a demuxer; fall back to the ProgressiveDemuxer.
LOG(INFO) << "Using ProgressiveDemuxer.";
return std::make_unique<ProgressiveDemuxer>(
media_task_runner_, data_source_.get(),
media_log_.get());
}
}
#endif // BUILDFLAG(ENABLE_FFMPEG)

#if BUILDFLAG(ENABLE_HLS_DEMUXER)
Expand Down
3 changes: 3 additions & 0 deletions media/filters/demuxer_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ class MEDIA_EXPORT DemuxerManager {

#if BUILDFLAG(ENABLE_FFMPEG)
std::unique_ptr<media::Demuxer> CreateFFmpegDemuxer();
#elif BUILDFLAG(USE_STARBOARD_MEDIA)
std::unique_ptr<media::Demuxer> CreateDemuxerExtensionWrapper();
std::unique_ptr<media::Demuxer> CreateProgressiveDemuxer();
#endif // BUILDFLAG(ENABLE_FFMPEG)

#if BUILDFLAG(ENABLE_HLS_DEMUXER)
Expand Down
35 changes: 35 additions & 0 deletions media/starboard/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

assert(is_cobalt, "This file builds for cobalt builds, not Chromium builds")

import("//media/media_options.gni")
import("//starboard/build/buildflags.gni")

source_set("starboard") {
Expand Down Expand Up @@ -81,6 +82,28 @@ source_set("starboard") {
"starboard_utils.cc",
"starboard_utils.h",
]
if (!media_use_ffmpeg) {
sources += [
"progressive/avc_access_unit.cc",
"progressive/avc_access_unit.h",
"progressive/avc_parser.cc",
"progressive/avc_parser.h",
"progressive/data_source_reader.cc",
"progressive/data_source_reader.h",
"progressive/demuxer_extension_wrapper.cc",
"progressive/demuxer_extension_wrapper.h",
"progressive/mp4_map.cc",
"progressive/mp4_map.h",
"progressive/mp4_parser.cc",
"progressive/mp4_parser.h",
"progressive/progressive_demuxer.cc",
"progressive/progressive_demuxer.h",
"progressive/progressive_parser.cc",
"progressive/progressive_parser.h",
"progressive/rbsp_stream.cc",
"progressive/rbsp_stream.h",
]
}
}

deps = [
Expand All @@ -91,6 +114,10 @@ source_set("starboard") {
"//starboard/common",
]

if (use_starboard_media && !media_use_ffmpeg) {
deps += [ "//third_party/abseil-cpp:absl" ]
}

configs += [ "//media:subcomponent_config" ]
}

Expand All @@ -102,6 +129,14 @@ source_set("unit_tests") {
"bidirectional_fit_reuse_allocator_test.cc",
"starboard_utils_test.cc",
]
if (!media_use_ffmpeg) {
sources += [
"progressive/demuxer_extension_wrapper_test.cc",
"progressive/mock_data_source_reader.h",
"progressive/mp4_map_unittest.cc",
"progressive/rbsp_stream_unittest.cc",
]
}
}
configs += [ "//media:media_config" ]
deps = [
Expand Down
Loading

0 comments on commit 2c6a160

Please sign in to comment.