forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic media tracks implementation for media stream parsers
This CL adds basic media::MediaTrack implementation, media::MediaTracks collection that associates media tracks with audio/video configs, and makes necessary changes in MSE stream parsers to pass around the MediaTracks collection instead of individual audio/video configs. BUG=249427, 249428 Review URL: https://codereview.chromium.org/1716503002 Cr-Commit-Position: refs/heads/master@{#378583}
- Loading branch information
servolk
authored and
Commit bot
committed
Mar 1, 2016
1 parent
45e1529
commit 95dc4ad
Showing
21 changed files
with
340 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright 2016 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "media/base/media_track.h" | ||
|
||
namespace media { | ||
|
||
MediaTrack::MediaTrack(Type type, | ||
const std::string& id, | ||
const std::string& kind, | ||
const std::string& label, | ||
const std::string& lang) | ||
: type_(type), id_(id), kind_(kind), label_(label), language_(lang) {} | ||
|
||
MediaTrack::~MediaTrack() {} | ||
|
||
} // namespace media |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2016 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef MEDIA_BASE_MEDIA_TRACK_H_ | ||
#define MEDIA_BASE_MEDIA_TRACK_H_ | ||
|
||
#include <string> | ||
|
||
#include "media/base/media_export.h" | ||
|
||
namespace media { | ||
|
||
class MEDIA_EXPORT MediaTrack { | ||
public: | ||
enum Type { Text, Audio, Video }; | ||
MediaTrack(Type type, | ||
const std::string& id, | ||
const std::string& kind, | ||
const std::string& label, | ||
const std::string& lang); | ||
~MediaTrack(); | ||
|
||
Type type() const { return type_; } | ||
|
||
const std::string& id() const { return id_; } | ||
const std::string& kind() const { return kind_; } | ||
const std::string& label() const { return label_; } | ||
const std::string& language() const { return language_; } | ||
|
||
private: | ||
Type type_; | ||
std::string id_; | ||
std::string kind_; | ||
std::string label_; | ||
std::string language_; | ||
}; | ||
|
||
} // namespace media | ||
|
||
#endif // MEDIA_BASE_MEDIA_TRACK_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Copyright 2016 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "media/base/media_tracks.h" | ||
|
||
#include "base/bind.h" | ||
#include "media/base/audio_decoder_config.h" | ||
#include "media/base/video_decoder_config.h" | ||
|
||
namespace media { | ||
|
||
MediaTracks::MediaTracks() {} | ||
|
||
MediaTracks::~MediaTracks() {} | ||
|
||
void MediaTracks::AddAudioTrack(const AudioDecoderConfig& config, | ||
const std::string& id, | ||
const std::string& kind, | ||
const std::string& label, | ||
const std::string& language) { | ||
DCHECK(config.IsValidConfig()); | ||
CHECK(audio_configs_.find(id) == audio_configs_.end()); | ||
scoped_ptr<MediaTrack> track = make_scoped_ptr( | ||
new MediaTrack(MediaTrack::Audio, id, kind, label, language)); | ||
tracks_.push_back(std::move(track)); | ||
audio_configs_[id] = config; | ||
} | ||
|
||
void MediaTracks::AddVideoTrack(const VideoDecoderConfig& config, | ||
const std::string& id, | ||
const std::string& kind, | ||
const std::string& label, | ||
const std::string& language) { | ||
DCHECK(config.IsValidConfig()); | ||
CHECK(video_configs_.find(id) == video_configs_.end()); | ||
scoped_ptr<MediaTrack> track = make_scoped_ptr( | ||
new MediaTrack(MediaTrack::Video, id, kind, label, language)); | ||
tracks_.push_back(std::move(track)); | ||
video_configs_[id] = config; | ||
} | ||
|
||
const AudioDecoderConfig& MediaTracks::getAudioConfig( | ||
const std::string& id) const { | ||
auto it = audio_configs_.find(id); | ||
if (it != audio_configs_.end()) | ||
return it->second; | ||
static AudioDecoderConfig invalidConfig; | ||
return invalidConfig; | ||
} | ||
|
||
const VideoDecoderConfig& MediaTracks::getVideoConfig( | ||
const std::string& id) const { | ||
auto it = video_configs_.find(id); | ||
if (it != video_configs_.end()) | ||
return it->second; | ||
static VideoDecoderConfig invalidConfig; | ||
return invalidConfig; | ||
} | ||
|
||
const AudioDecoderConfig& MediaTracks::getFirstAudioConfig() const { | ||
for (const auto& track : tracks()) { | ||
if (track->type() == MediaTrack::Audio) { | ||
return getAudioConfig(track->id()); | ||
} | ||
} | ||
static AudioDecoderConfig invalidConfig; | ||
return invalidConfig; | ||
} | ||
|
||
const VideoDecoderConfig& MediaTracks::getFirstVideoConfig() const { | ||
for (const auto& track : tracks()) { | ||
if (track->type() == MediaTrack::Video) { | ||
return getVideoConfig(track->id()); | ||
} | ||
} | ||
static VideoDecoderConfig invalidConfig; | ||
return invalidConfig; | ||
} | ||
|
||
} // namespace media |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright 2016 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef MEDIA_BASE_MEDIA_TRACKS_H_ | ||
#define MEDIA_BASE_MEDIA_TRACKS_H_ | ||
|
||
#include <map> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "base/macros.h" | ||
#include "base/memory/scoped_ptr.h" | ||
#include "media/base/media_export.h" | ||
#include "media/base/media_track.h" | ||
|
||
namespace media { | ||
|
||
class AudioDecoderConfig; | ||
class VideoDecoderConfig; | ||
|
||
class MEDIA_EXPORT MediaTracks { | ||
public: | ||
typedef std::vector<scoped_ptr<MediaTrack>> MediaTracksCollection; | ||
|
||
MediaTracks(); | ||
~MediaTracks(); | ||
|
||
// Callers need to ensure that track id is unique. | ||
void AddAudioTrack(const AudioDecoderConfig& config, | ||
const std::string& id, | ||
const std::string& kind, | ||
const std::string& label, | ||
const std::string& language); | ||
// Callers need to ensure that track id is unique. | ||
void AddVideoTrack(const VideoDecoderConfig& config, | ||
const std::string& id, | ||
const std::string& kind, | ||
const std::string& label, | ||
const std::string& language); | ||
|
||
const MediaTracksCollection& tracks() const { return tracks_; } | ||
|
||
const AudioDecoderConfig& getAudioConfig(const std::string& id) const; | ||
const VideoDecoderConfig& getVideoConfig(const std::string& id) const; | ||
|
||
// TODO(servolk): These are temporary helpers useful until all code paths are | ||
// converted to properly handle multiple media tracks. | ||
const AudioDecoderConfig& getFirstAudioConfig() const; | ||
const VideoDecoderConfig& getFirstVideoConfig() const; | ||
|
||
private: | ||
MediaTracksCollection tracks_; | ||
std::map<std::string, AudioDecoderConfig> audio_configs_; | ||
std::map<std::string, VideoDecoderConfig> video_configs_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(MediaTracks); | ||
}; | ||
|
||
} // namespace media | ||
|
||
#endif // MEDIA_BASE_MEDIA_TRACKS_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.