Index: services/media/framework/stream_type.cc |
diff --git a/services/media/framework/stream_type.cc b/services/media/framework/stream_type.cc |
index 0fad31323ddea3ca375725919fb3224c374339ec..08e24203908ae965fdcd0b97a4a826076947e9e5 100644 |
--- a/services/media/framework/stream_type.cc |
+++ b/services/media/framework/stream_type.cc |
@@ -17,125 +17,119 @@ std::unique_ptr<Bytes> Bytes::Clone() const { |
return std::unique_ptr<Bytes>(new Bytes(*this)); |
} |
-StreamType::StreamType(Scheme scheme) : scheme_(scheme) {} |
+// These must match the definitions in media_types.mojom. This is verfied by |
+// the KnownEncodingsMatch function in framework_mojo/mojo_type_conversion.cc. |
+// Changes to this list should be reflected there. |
+const char* StreamType::kAudioEncodingLpcm = "lpcm"; |
+const char* StreamType::kAudioEncodingVorbis = "vorbis"; |
+const char* StreamType::kVideoEncodingUncompressed = "uncompressed_video"; |
+const char* StreamType::kVideoEncodingTheora = "theora"; |
+ |
+StreamType::StreamType(Medium medium, |
+ const std::string& encoding, |
+ std::unique_ptr<Bytes> encoding_parameters) |
+ : medium_(medium), |
+ encoding_(encoding), |
+ encoding_parameters_(std::move(encoding_parameters)) {} |
StreamType::~StreamType() {} |
-const MultiplexedStreamType* StreamType::multiplexed() const { |
- NOTREACHED(); |
+const AudioStreamType* StreamType::audio() const { |
+ LOG(ERROR) << "audio method called on non-audio stream type"; |
return nullptr; |
} |
-const LpcmStreamType* StreamType::lpcm() const { |
- NOTREACHED(); |
+const VideoStreamType* StreamType::video() const { |
+ LOG(ERROR) << "video method called on non-video stream type"; |
return nullptr; |
} |
-const CompressedAudioStreamType* StreamType::compressed_audio() const { |
- NOTREACHED(); |
+const TextStreamType* StreamType::text() const { |
+ LOG(ERROR) << "text method called on non-text stream type"; |
return nullptr; |
} |
-const VideoStreamType* StreamType::video() const { |
- NOTREACHED(); |
+const SubpictureStreamType* StreamType::subpicture() const { |
+ LOG(ERROR) << "subpicture method called on non-subpicture stream type"; |
return nullptr; |
} |
std::unique_ptr<StreamType> StreamType::Clone() const { |
- return Create(scheme()); |
+ return Create(medium(), encoding(), SafeClone(encoding_parameters())); |
} |
-StreamTypeSet::StreamTypeSet(StreamType::Scheme scheme) : scheme_(scheme) {} |
+StreamTypeSet::StreamTypeSet(StreamType::Medium medium, |
+ const std::vector<std::string>& encodings) |
+ : medium_(medium), encodings_(encodings) {} |
StreamTypeSet::~StreamTypeSet() {} |
-const MultiplexedStreamTypeSet* StreamTypeSet::multiplexed() const { |
- NOTREACHED(); |
+const AudioStreamTypeSet* StreamTypeSet::audio() const { |
+ LOG(ERROR) << "audio method called on non-audio stream type set"; |
return nullptr; |
} |
-const LpcmStreamTypeSet* StreamTypeSet::lpcm() const { |
- NOTREACHED(); |
+const VideoStreamTypeSet* StreamTypeSet::video() const { |
+ LOG(ERROR) << "video method called on non-video stream type set"; |
return nullptr; |
} |
-const CompressedAudioStreamTypeSet* StreamTypeSet::compressed_audio() const { |
- NOTREACHED(); |
+const TextStreamTypeSet* StreamTypeSet::text() const { |
+ LOG(ERROR) << "text method called on non-text stream type set"; |
return nullptr; |
} |
-const VideoStreamTypeSet* StreamTypeSet::video() const { |
- NOTREACHED(); |
+const SubpictureStreamTypeSet* StreamTypeSet::subpicture() const { |
+ LOG(ERROR) << "subpicture method called on non-subpicture stream type set"; |
return nullptr; |
} |
std::unique_ptr<StreamTypeSet> StreamTypeSet::Clone() const { |
- return Create(scheme()); |
-} |
- |
-MultiplexedStreamType::MultiplexedStreamType( |
- std::unique_ptr<StreamType> multiplex_type, |
- std::unique_ptr<std::vector<std::unique_ptr<StreamType>>> substream_types) |
- : StreamType(Scheme::kMultiplexed), |
- multiplex_type_(std::move(multiplex_type)), |
- substream_types_(std::move(substream_types)) {} |
- |
-MultiplexedStreamType::~MultiplexedStreamType() {} |
- |
-const MultiplexedStreamType* MultiplexedStreamType::multiplexed() const { |
- return this; |
+ return Create(medium(), encodings()); |
} |
-std::unique_ptr<StreamType> MultiplexedStreamType::Clone() const { |
- return Create(SafeClone(multiplex_type()), SafeClone(substream_types())); |
-} |
- |
-MultiplexedStreamTypeSet::MultiplexedStreamTypeSet( |
- std::unique_ptr<StreamTypeSet> multiplex_type_set, |
- std::unique_ptr<std::vector<std::unique_ptr<StreamTypeSet>>> |
- substream_type_sets) |
- : StreamTypeSet(StreamType::Scheme::kMultiplexed), |
- multiplex_type_set_(std::move(multiplex_type_set)), |
- substream_type_sets_(std::move(substream_type_sets)) {} |
- |
-MultiplexedStreamTypeSet::~MultiplexedStreamTypeSet() {} |
- |
-const MultiplexedStreamTypeSet* MultiplexedStreamTypeSet::multiplexed() const { |
- return this; |
-} |
+bool StreamTypeSet::IncludesEncoding(const std::string encoding) { |
+ for (const std::string set_encoding : encodings_) { |
+ if (set_encoding == encoding) { |
+ return true; |
+ } |
+ } |
-std::unique_ptr<StreamTypeSet> MultiplexedStreamTypeSet::Clone() const { |
- return Create(SafeClone(multiplex_type_set()), |
- SafeClone(substream_type_sets())); |
+ return false; |
} |
-LpcmStreamType::LpcmStreamType(SampleFormat sample_format, |
- uint32_t channels, |
- uint32_t frames_per_second) |
- : LpcmStreamType(Scheme::kLpcm, |
- sample_format, |
- channels, |
- frames_per_second) {} |
- |
-LpcmStreamType::LpcmStreamType(Scheme scheme, |
- SampleFormat sample_format, |
- uint32_t channels, |
- uint32_t frames_per_second) |
- : StreamType(scheme), |
+AudioStreamType::AudioStreamType(const std::string& encoding, |
+ std::unique_ptr<Bytes> encoding_parameters, |
+ SampleFormat sample_format, |
+ uint32_t channels, |
+ uint32_t frames_per_second) |
+ : StreamType(StreamType::Medium::kAudio, |
+ encoding, |
+ std::move(encoding_parameters)), |
sample_format_(sample_format), |
channels_(channels), |
frames_per_second_(frames_per_second), |
sample_size_(SampleSizeFromFormat(sample_format)) {} |
-LpcmStreamType::~LpcmStreamType() {} |
+AudioStreamType::AudioStreamType(const AudioStreamType& other) |
+ : AudioStreamType(other.encoding(), |
+ SafeClone(other.encoding_parameters()), |
+ other.sample_format(), |
+ other.channels(), |
+ other.frames_per_second()) {} |
-const LpcmStreamType* LpcmStreamType::lpcm() const { |
+AudioStreamType::~AudioStreamType() {} |
+ |
+const AudioStreamType* AudioStreamType::audio() const { |
return this; |
} |
// static |
-uint32_t LpcmStreamType::SampleSizeFromFormat(SampleFormat sample_format) { |
+uint32_t AudioStreamType::SampleSizeFromFormat(SampleFormat sample_format) { |
switch (sample_format) { |
+ case SampleFormat::kAny: |
+ LOG(ERROR) << "sample size requested for SampleFormat::kAny"; |
+ abort(); |
case SampleFormat::kUnsigned8: |
return sizeof(uint8_t); |
case SampleFormat::kSigned16: |
@@ -144,128 +138,62 @@ uint32_t LpcmStreamType::SampleSizeFromFormat(SampleFormat sample_format) { |
return sizeof(int32_t); |
case SampleFormat::kFloat: |
return sizeof(float); |
- case SampleFormat::kUnknown: |
- case SampleFormat::kAny: |
- return 0; |
} |
return 0; |
} |
-std::unique_ptr<StreamType> LpcmStreamType::Clone() const { |
- return Create(sample_format(), channels(), frames_per_second()); |
+std::unique_ptr<StreamType> AudioStreamType::Clone() const { |
+ return Create(encoding(), SafeClone(encoding_parameters()), sample_format(), |
+ channels(), frames_per_second()); |
} |
-LpcmStreamTypeSet::LpcmStreamTypeSet(LpcmStreamType::SampleFormat sample_format, |
- Range<uint32_t> channels, |
- Range<uint32_t> frames_per_second) |
- : LpcmStreamTypeSet(StreamType::Scheme::kLpcm, |
- sample_format, |
- channels, |
- frames_per_second) {} |
- |
-LpcmStreamTypeSet::LpcmStreamTypeSet(StreamType::Scheme scheme, |
- LpcmStreamType::SampleFormat sample_format, |
- Range<uint32_t> channels, |
- Range<uint32_t> frames_per_second) |
- : StreamTypeSet(scheme), |
+AudioStreamTypeSet::AudioStreamTypeSet( |
+ const std::vector<std::string>& encodings, |
+ AudioStreamType::SampleFormat sample_format, |
+ Range<uint32_t> channels, |
+ Range<uint32_t> frames_per_second) |
+ : StreamTypeSet(StreamType::Medium::kAudio, encodings), |
sample_format_(sample_format), |
channels_(channels), |
frames_per_second_(frames_per_second) {} |
-LpcmStreamTypeSet::~LpcmStreamTypeSet() {} |
+AudioStreamTypeSet::~AudioStreamTypeSet() {} |
-const LpcmStreamTypeSet* LpcmStreamTypeSet::lpcm() const { |
+const AudioStreamTypeSet* AudioStreamTypeSet::audio() const { |
return this; |
} |
-bool LpcmStreamTypeSet::contains(const LpcmStreamType& type) const { |
+bool AudioStreamTypeSet::contains(const AudioStreamType& type) const { |
return (sample_format() == type.sample_format() || |
- sample_format() == LpcmStreamType::SampleFormat::kAny) && |
+ sample_format() == AudioStreamType::SampleFormat::kAny) && |
channels().contains(type.frames_per_second()) && |
frames_per_second().contains(type.frames_per_second()); |
} |
-std::unique_ptr<StreamTypeSet> LpcmStreamTypeSet::Clone() const { |
- return Create(sample_format(), channels(), frames_per_second()); |
-} |
- |
-CompressedAudioStreamType::CompressedAudioStreamType( |
- AudioEncoding encoding, |
- SampleFormat sample_format, |
- uint32_t channels, |
- uint32_t frames_per_second, |
- std::unique_ptr<Bytes> encoding_details) |
- : LpcmStreamType(Scheme::kCompressedAudio, |
- sample_format, |
- channels, |
- frames_per_second), |
- encoding_(encoding), |
- encoding_details_(std::move(encoding_details)) {} |
- |
-CompressedAudioStreamType::~CompressedAudioStreamType() {} |
- |
-const CompressedAudioStreamType* CompressedAudioStreamType::compressed_audio() |
- const { |
- return this; |
-} |
- |
-std::unique_ptr<StreamType> CompressedAudioStreamType::Clone() const { |
- return Create(encoding(), sample_format(), channels(), frames_per_second(), |
- SafeClone(encoding_details())); |
-} |
- |
-CompressedAudioStreamTypeSet::CompressedAudioStreamTypeSet( |
- CompressedAudioStreamType::AudioEncoding encoding, |
- CompressedAudioStreamType::SampleFormat sample_format, |
- Range<uint32_t> channels, |
- Range<uint32_t> frames_per_second) |
- : LpcmStreamTypeSet(StreamType::Scheme::kCompressedAudio, |
- sample_format, |
- channels, |
- frames_per_second), |
- encoding_(encoding) {} |
- |
-CompressedAudioStreamTypeSet::~CompressedAudioStreamTypeSet() {} |
- |
-const CompressedAudioStreamTypeSet* |
-CompressedAudioStreamTypeSet::compressed_audio() const { |
- return this; |
+std::unique_ptr<StreamTypeSet> AudioStreamTypeSet::Clone() const { |
+ return Create(encodings(), sample_format(), channels(), frames_per_second()); |
} |
-bool CompressedAudioStreamTypeSet::contains( |
- const CompressedAudioStreamType& type) const { |
- return (encoding() == type.encoding() || |
- encoding() == CompressedAudioStreamType::AudioEncoding::kAny) && |
- (sample_format() == type.sample_format() || |
- sample_format() == LpcmStreamType::SampleFormat::kAny) && |
- channels().contains(type.frames_per_second()) && |
- frames_per_second().contains(type.frames_per_second()); |
-} |
- |
-std::unique_ptr<StreamTypeSet> CompressedAudioStreamTypeSet::Clone() const { |
- return Create(encoding(), sample_format(), channels(), frames_per_second()); |
-} |
- |
-VideoStreamType::VideoStreamType(VideoEncoding encoding, |
+VideoStreamType::VideoStreamType(const std::string& encoding, |
+ std::unique_ptr<Bytes> encoding_parameters, |
VideoProfile profile, |
PixelFormat pixel_format, |
ColorSpace color_space, |
uint32_t width, |
uint32_t height, |
uint32_t coded_width, |
- uint32_t coded_height, |
- std::unique_ptr<Bytes> encoding_details) |
- : StreamType(StreamType::Scheme::kVideo), |
- encoding_(encoding), |
+ uint32_t coded_height) |
+ : StreamType(StreamType::Medium::kVideo, |
+ encoding, |
+ std::move(encoding_parameters)), |
profile_(profile), |
pixel_format_(pixel_format), |
color_space_(color_space), |
width_(width), |
height_(height), |
coded_width_(coded_width), |
- coded_height_(coded_height), |
- encoding_details_(std::move(encoding_details)) {} |
+ coded_height_(coded_height) {} |
VideoStreamType::~VideoStreamType() {} |
@@ -274,16 +202,16 @@ const VideoStreamType* VideoStreamType::video() const { |
} |
std::unique_ptr<StreamType> VideoStreamType::Clone() const { |
- return Create(encoding(), profile(), pixel_format(), color_space(), width(), |
- height(), coded_width(), coded_height(), |
- SafeClone(encoding_details())); |
+ return Create(encoding(), SafeClone(encoding_parameters()), profile(), |
+ pixel_format(), color_space(), width(), height(), coded_width(), |
+ coded_height()); |
} |
-VideoStreamTypeSet::VideoStreamTypeSet(VideoStreamType::VideoEncoding encoding, |
- Range<uint32_t> width, |
- Range<uint32_t> height) |
- : StreamTypeSet(StreamType::Scheme::kVideo), |
- encoding_(encoding), |
+VideoStreamTypeSet::VideoStreamTypeSet( |
+ const std::vector<std::string>& encodings, |
+ Range<uint32_t> width, |
+ Range<uint32_t> height) |
+ : StreamTypeSet(StreamType::Medium::kVideo, encodings), |
width_(width), |
height_(height) {} |
@@ -294,7 +222,67 @@ const VideoStreamTypeSet* VideoStreamTypeSet::video() const { |
} |
std::unique_ptr<StreamTypeSet> VideoStreamTypeSet::Clone() const { |
- return Create(encoding(), width(), height()); |
+ return Create(encodings(), width(), height()); |
+} |
+ |
+TextStreamType::TextStreamType(const std::string& encoding, |
+ std::unique_ptr<Bytes> encoding_parameters) |
+ : StreamType(StreamType::Medium::kText, |
+ encoding, |
+ std::move(encoding_parameters)) {} |
+ |
+TextStreamType::~TextStreamType() {} |
+ |
+const TextStreamType* TextStreamType::text() const { |
+ return this; |
+} |
+ |
+std::unique_ptr<StreamType> TextStreamType::Clone() const { |
+ return Create(encoding(), SafeClone(encoding_parameters())); |
+} |
+ |
+TextStreamTypeSet::TextStreamTypeSet(const std::vector<std::string>& encodings) |
+ : StreamTypeSet(StreamType::Medium::kText, encodings) {} |
+ |
+TextStreamTypeSet::~TextStreamTypeSet() {} |
+ |
+const TextStreamTypeSet* TextStreamTypeSet::text() const { |
+ return this; |
+} |
+ |
+std::unique_ptr<StreamTypeSet> TextStreamTypeSet::Clone() const { |
+ return Create(encodings()); |
+} |
+ |
+SubpictureStreamType::SubpictureStreamType( |
+ const std::string& encoding, |
+ std::unique_ptr<Bytes> encoding_parameters) |
+ : StreamType(StreamType::Medium::kSubpicture, |
+ encoding, |
+ std::move(encoding_parameters)) {} |
+ |
+SubpictureStreamType::~SubpictureStreamType() {} |
+ |
+const SubpictureStreamType* SubpictureStreamType::subpicture() const { |
+ return this; |
+} |
+ |
+std::unique_ptr<StreamType> SubpictureStreamType::Clone() const { |
+ return Create(encoding(), SafeClone(encoding_parameters())); |
+} |
+ |
+SubpictureStreamTypeSet::SubpictureStreamTypeSet( |
+ const std::vector<std::string>& encodings) |
+ : StreamTypeSet(StreamType::Medium::kSubpicture, encodings) {} |
+ |
+SubpictureStreamTypeSet::~SubpictureStreamTypeSet() {} |
+ |
+const SubpictureStreamTypeSet* SubpictureStreamTypeSet::subpicture() const { |
+ return this; |
+} |
+ |
+std::unique_ptr<StreamTypeSet> SubpictureStreamTypeSet::Clone() const { |
+ return Create(encodings()); |
} |
} // namespace media |