Skip to content

Commit

Permalink
Unify media track info reporting on a demuxer level
Browse files Browse the repository at this point in the history
This will work for both FFmpegDemuxer and MSE/ChunkDemuxer

Review URL: https://codereview.chromium.org/1727243002

Cr-Commit-Position: refs/heads/master@{#379449}
  • Loading branch information
servolk authored and Commit bot committed Mar 5, 2016
1 parent ebeddad commit 81e01e0
Show file tree
Hide file tree
Showing 18 changed files with 189 additions and 95 deletions.
7 changes: 6 additions & 1 deletion chromecast/media/cma/test/frame_segmenter_for_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "media/base/decoder_buffer.h"
#include "media/base/demuxer.h"
#include "media/base/media_log.h"
#include "media/base/media_tracks.h"
#include "media/base/test_helpers.h"
#include "media/filters/ffmpeg_demuxer.h"
#include "media/filters/file_data_source.h"
Expand Down Expand Up @@ -269,6 +270,9 @@ void OnEncryptedMediaInitData(::media::EmeInitDataType init_data_type,
LOG(FATAL) << "Unexpected test failure: file is encrypted.";
}

void OnMediaTracksUpdated(scoped_ptr<::media::MediaTracks> tracks) {
}

void OnNewBuffer(BufferList* buffer_list,
const base::Closure& finished_cb,
::media::DemuxerStream::Status status,
Expand Down Expand Up @@ -310,7 +314,8 @@ DemuxResult FFmpegDemuxForTest(const base::FilePath& filepath,

::media::FFmpegDemuxer demuxer(
base::ThreadTaskRunnerHandle::Get(), &data_source,
base::Bind(&OnEncryptedMediaInitData), new ::media::MediaLog());
base::Bind(&OnEncryptedMediaInitData), base::Bind(&OnMediaTracksUpdated),
new ::media::MediaLog());
::media::WaitableMessageLoopEvent init_event;
demuxer.Initialize(&fake_demuxer_host,
init_event.GetPipelineStatusCB(),
Expand Down
6 changes: 6 additions & 0 deletions media/base/demuxer.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
namespace media {

class TextTrackConfig;
class MediaTracks;

class MEDIA_EXPORT DemuxerHost {
public:
Expand Down Expand Up @@ -64,6 +65,11 @@ class MEDIA_EXPORT Demuxer : public DemuxerStreamProvider {
const std::vector<uint8_t>& init_data)>
EncryptedMediaInitDataCB;

// Notifies demuxer clients that media track configuration has been updated
// (e.g. the inital stream metadata has been parsed successfully, or a new
// init segment has been parsed successfully in MSE case).
typedef base::Callback<void(scoped_ptr<MediaTracks>)> MediaTracksUpdatedCB;

Demuxer();
~Demuxer() override;

Expand Down
10 changes: 9 additions & 1 deletion media/base/demuxer_perftest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "build/build_config.h"
#include "media/base/media.h"
#include "media/base/media_log.h"
#include "media/base/media_tracks.h"
#include "media/base/test_data_util.h"
#include "media/base/timestamp_constants.h"
#include "media/filters/ffmpeg_demuxer.h"
Expand Down Expand Up @@ -54,6 +55,10 @@ static void OnEncryptedMediaInitData(EmeInitDataType init_data_type,
VLOG(0) << "File is encrypted.";
}

static void OnMediaTracksUpdated(scoped_ptr<MediaTracks> tracks) {
VLOG(0) << "Got media tracks info, tracks = " << tracks->tracks().size();
}

typedef std::vector<media::DemuxerStream* > Streams;

// Simulates playback reading requirements by reading from each stream
Expand Down Expand Up @@ -183,8 +188,11 @@ static void RunDemuxerBenchmark(const std::string& filename) {

Demuxer::EncryptedMediaInitDataCB encrypted_media_init_data_cb =
base::Bind(&OnEncryptedMediaInitData);
Demuxer::MediaTracksUpdatedCB tracks_updated_cb =
base::Bind(&OnMediaTracksUpdated);
FFmpegDemuxer demuxer(message_loop.task_runner(), &data_source,
encrypted_media_init_data_cb, new MediaLog());
encrypted_media_init_data_cb, tracks_updated_cb,
new MediaLog());

demuxer.Initialize(&demuxer_host,
base::Bind(&QuitLoopWithStatus, &message_loop),
Expand Down
15 changes: 14 additions & 1 deletion media/blink/webmediaplayer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,14 @@ void WebMediaPlayerImpl::OnEncryptedMediaInitData(
base::saturated_cast<unsigned int>(init_data.size()));
}

void WebMediaPlayerImpl::OnFFmpegMediaTracksUpdated(
scoped_ptr<MediaTracks> tracks) {
// For MSE/chunk_demuxer case the media track updates are handled by
// WebSourceBufferImpl.
DCHECK(demuxer_.get());
DCHECK(!chunk_demuxer_);
}

void WebMediaPlayerImpl::OnWaitingForDecryptionKey() {
encrypted_client_->didBlockPlaybackWaitingForKey();

Expand Down Expand Up @@ -1205,8 +1213,13 @@ void WebMediaPlayerImpl::StartPipeline() {
DCHECK(data_source_);

#if !defined(MEDIA_DISABLE_FFMPEG)
Demuxer::MediaTracksUpdatedCB media_tracks_updated_cb =
base::Bind(&WebMediaPlayerImpl::OnFFmpegMediaTracksUpdated,
base::Unretained(this));

demuxer_.reset(new FFmpegDemuxer(media_task_runner_, data_source_.get(),
encrypted_media_init_data_cb, media_log_));
encrypted_media_init_data_cb,
media_tracks_updated_cb, media_log_));
#else
OnPipelineError(PipelineStatus::DEMUXER_ERROR_COULD_NOT_OPEN);
return;
Expand Down
6 changes: 6 additions & 0 deletions media/blink/webmediaplayer_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "base/memory/weak_ptr.h"
#include "base/threading/thread.h"
#include "build/build_config.h"
#include "media/base/media_tracks.h"
#include "media/base/pipeline_impl.h"
#include "media/base/renderer_factory.h"
#include "media/base/surface_manager.h"
Expand Down Expand Up @@ -256,6 +257,11 @@ class MEDIA_BLINK_EXPORT WebMediaPlayerImpl
void OnEncryptedMediaInitData(EmeInitDataType init_data_type,
const std::vector<uint8_t>& init_data);

// Called when the FFmpegDemuxer encounters new media tracks. This is only
// invoked when using FFmpegDemuxer, since MSE/ChunkDemuxer handle media
// tracks separately in WebSourceBufferImpl.
void OnFFmpegMediaTracksUpdated(scoped_ptr<MediaTracks> tracks);

// Called when a decoder detects that the key needed to decrypt the stream
// is not available.
void OnWaitingForDecryptionKey();
Expand Down
12 changes: 6 additions & 6 deletions media/blink/websourcebuffer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ WebSourceBufferImpl::WebSourceBufferImpl(
client_(NULL),
append_window_end_(kInfiniteDuration()) {
DCHECK(demuxer_);
demuxer_->SetTracksWatcher(
id, base::Bind(&WebSourceBufferImpl::InitSegmentReceived,
base::Unretained(this)));
}

WebSourceBufferImpl::~WebSourceBufferImpl() {
Expand Down Expand Up @@ -99,11 +102,8 @@ void WebSourceBufferImpl::append(
unsigned length,
double* timestamp_offset) {
base::TimeDelta old_offset = timestamp_offset_;
demuxer_->AppendData(id_, data, length,
append_window_start_, append_window_end_,
&timestamp_offset_,
base::Bind(&WebSourceBufferImpl::InitSegmentReceived,
base::Unretained(this)));
demuxer_->AppendData(id_, data, length, append_window_start_,
append_window_end_, &timestamp_offset_);

// Coded frame processing may update the timestamp offset. If the caller
// provides a non-NULL |timestamp_offset| and frame processing changes the
Expand Down Expand Up @@ -159,7 +159,7 @@ void WebSourceBufferImpl::removedFromMediaSource() {
client_ = NULL;
}

void WebSourceBufferImpl::InitSegmentReceived(const MediaTracks& tracks) {
void WebSourceBufferImpl::InitSegmentReceived(scoped_ptr<MediaTracks> tracks) {
DVLOG(1) << __FUNCTION__;
// TODO(servolk): Implement passing MediaTrack info to blink level.
// https://crbug.com/249428
Expand Down
3 changes: 2 additions & 1 deletion media/blink/websourcebuffer_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "base/compiler_specific.h"
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "base/time/time.h"
#include "third_party/WebKit/public/platform/WebSourceBuffer.h"

Expand Down Expand Up @@ -43,7 +44,7 @@ class WebSourceBufferImpl : public blink::WebSourceBuffer {
private:
// Demuxer callback handler to process an initialization segment received
// during an append() call.
void InitSegmentReceived(const MediaTracks& tracks);
void InitSegmentReceived(scoped_ptr<MediaTracks> tracks);

std::string id_;
ChunkDemuxer* demuxer_; // Owned by WebMediaPlayerImpl.
Expand Down
29 changes: 16 additions & 13 deletions media/filters/chunk_demuxer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,14 @@ ChunkDemuxer::Status ChunkDemuxer::AddId(const std::string& id,
return kOk;
}

void ChunkDemuxer::SetTracksWatcher(
const std::string& id,
const MediaTracksUpdatedCB& tracks_updated_cb) {
base::AutoLock auto_lock(lock_);
CHECK(IsValidId(id));
source_state_map_[id]->SetTracksWatcher(tracks_updated_cb);
}

void ChunkDemuxer::RemoveId(const std::string& id) {
base::AutoLock auto_lock(lock_);
CHECK(IsValidId(id));
Expand Down Expand Up @@ -596,19 +604,16 @@ bool ChunkDemuxer::EvictCodedFrames(const std::string& id,
return itr->second->EvictCodedFrames(media_time_dts, newDataSize);
}

void ChunkDemuxer::AppendData(
const std::string& id,
const uint8_t* data,
size_t length,
TimeDelta append_window_start,
TimeDelta append_window_end,
TimeDelta* timestamp_offset,
const MediaSourceState::InitSegmentReceivedCB& init_segment_received_cb) {
void ChunkDemuxer::AppendData(const std::string& id,
const uint8_t* data,
size_t length,
TimeDelta append_window_start,
TimeDelta append_window_end,
TimeDelta* timestamp_offset) {
DVLOG(1) << "AppendData(" << id << ", " << length << ")";

DCHECK(!id.empty());
DCHECK(timestamp_offset);
DCHECK(!init_segment_received_cb.is_null());

Ranges<TimeDelta> ranges;

Expand All @@ -629,11 +634,9 @@ void ChunkDemuxer::AppendData(
case INITIALIZING:
case INITIALIZED:
DCHECK(IsValidId(id));
if (!source_state_map_[id]->Append(data, length,
append_window_start,
if (!source_state_map_[id]->Append(data, length, append_window_start,
append_window_end,
timestamp_offset,
init_segment_received_cb)) {
timestamp_offset)) {
ReportError_Locked(PIPELINE_ERROR_DECODE);
return;
}
Expand Down
21 changes: 11 additions & 10 deletions media/filters/chunk_demuxer.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ class MEDIA_EXPORT ChunkDemuxer : public Demuxer {
Status AddId(const std::string& id, const std::string& type,
std::vector<std::string>& codecs);

// Notifies a caller via |tracks_updated_cb| that the set of media tracks
// for a given |id| has changed.
void SetTracksWatcher(const std::string& id,
const MediaTracksUpdatedCB& tracks_updated_cb);

// Removed an ID & associated resources that were previously added with
// AddId().
void RemoveId(const std::string& id);
Expand All @@ -233,16 +238,12 @@ class MEDIA_EXPORT ChunkDemuxer : public Demuxer {
// |append_window_start| and |append_window_end| correspond to the MSE spec's
// similarly named source buffer attributes that are used in coded frame
// processing.
// |init_segment_received_cb| is run for each newly successfully parsed
// initialization segment.
void AppendData(
const std::string& id,
const uint8_t* data,
size_t length,
base::TimeDelta append_window_start,
base::TimeDelta append_window_end,
base::TimeDelta* timestamp_offset,
const MediaSourceState::InitSegmentReceivedCB& init_segment_received_cb);
void AppendData(const std::string& id,
const uint8_t* data,
size_t length,
base::TimeDelta append_window_start,
base::TimeDelta append_window_end,
base::TimeDelta* timestamp_offset);

// Aborts parsing the current segment and reset the parser to a state where
// it can accept a new segment.
Expand Down
Loading

0 comments on commit 81e01e0

Please sign in to comment.