media_track.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Copyright 2016 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef MEDIA_BASE_MEDIA_TRACK_H_
  5. #define MEDIA_BASE_MEDIA_TRACK_H_
  6. #include <string>
  7. #include "base/types/strong_alias.h"
  8. #include "media/base/media_export.h"
  9. #include "media/base/stream_parser.h"
  10. namespace media {
  11. class MEDIA_EXPORT MediaTrack {
  12. public:
  13. enum Type { Text, Audio, Video };
  14. using Id = base::StrongAlias<class IdTag, std::string>;
  15. using Kind = base::StrongAlias<class KindTag, std::string>;
  16. using Label = base::StrongAlias<class LabelTag, std::string>;
  17. using Language = base::StrongAlias<class LanguageTag, std::string>;
  18. MediaTrack(Type type,
  19. StreamParser::TrackId bytestream_track_id,
  20. const Kind& kind,
  21. const Label& label,
  22. const Language& lang);
  23. ~MediaTrack();
  24. Type type() const { return type_; }
  25. StreamParser::TrackId bytestream_track_id() const {
  26. return bytestream_track_id_;
  27. }
  28. const Kind& kind() const { return kind_; }
  29. const Label& label() const { return label_; }
  30. const Language& language() const { return language_; }
  31. Id id() const { return id_; }
  32. void set_id(Id id) {
  33. DCHECK(id_.value().empty());
  34. DCHECK(!id.value().empty());
  35. id_ = id;
  36. }
  37. private:
  38. Type type_;
  39. // |bytestream_track_id_| is read from the bytestream and is guaranteed to be
  40. // unique only within the scope of single bytestream's initialization segment.
  41. // But we might have multiple bytestreams (MediaSource might have multiple
  42. // SourceBuffers attached to it, which translates into ChunkDemuxer having
  43. // multiple SourceBufferStates and multiple bytestreams) or subsequent init
  44. // segments may redefine the bytestream ids. Thus bytestream track ids are not
  45. // guaranteed to be unique at the Demuxer and HTMLMediaElement level. So we
  46. // generate truly unique media track |id_| on the Demuxer level.
  47. StreamParser::TrackId bytestream_track_id_;
  48. Id id_;
  49. // These properties are read from input streams by stream parsers as specified
  50. // in https://dev.w3.org/html5/html-sourcing-inband-tracks/.
  51. Kind kind_;
  52. Label label_;
  53. Language language_;
  54. };
  55. // Helper for logging.
  56. MEDIA_EXPORT const char* TrackTypeToStr(MediaTrack::Type type);
  57. } // namespace media
  58. #endif // MEDIA_BASE_MEDIA_TRACK_H_