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