1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111
  112
  113
  114
  115
  116
  117
  118
  119
  120
  121
  122
  123

media / base / media_track.cc [blame]

// Copyright 2016 The Chromium Authors
// 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() = default;

const char* TrackTypeToStr(MediaTrack::Type type) {
  switch (type) {
    case MediaTrack::Type::kAudio:
      return "audio";
    case MediaTrack::Type::kVideo:
      return "video";
  }
  NOTREACHED();
}

// static
MediaTrack::Kind MediaTrack::VideoKindToString(MediaTrack::VideoKind kind) {
  switch (kind) {
    case MediaTrack::VideoKind::kAlternative:
      return MediaTrack::Kind{"alternative"};
    case MediaTrack::VideoKind::kCaptions:
      return MediaTrack::Kind{"captions"};
    case MediaTrack::VideoKind::kMain:
      return MediaTrack::Kind{"main"};
    case MediaTrack::VideoKind::kSign:
      return MediaTrack::Kind{"sign"};
    case MediaTrack::VideoKind::kSubtitles:
      return MediaTrack::Kind{"subtitles"};
    case MediaTrack::VideoKind::kCommentary:
      return MediaTrack::Kind{"commentary"};
    case MediaTrack::VideoKind::kNone:
      return MediaTrack::Kind{""};
  }
}

// static
MediaTrack::Kind MediaTrack::AudioKindToString(MediaTrack::AudioKind kind) {
  switch (kind) {
    case MediaTrack::AudioKind::kAlternative:
      return MediaTrack::Kind{"alternative"};
    case MediaTrack::AudioKind::kDescriptions:
      return MediaTrack::Kind{"descriptions"};
    case MediaTrack::AudioKind::kMain:
      return MediaTrack::Kind{"main"};
    case MediaTrack::AudioKind::kMainDescriptions:
      return MediaTrack::Kind{"main-desc"};
    case MediaTrack::AudioKind::kTranslation:
      return MediaTrack::Kind{"translation"};
    case MediaTrack::AudioKind::kCommentary:
      return MediaTrack::Kind{"commentary"};
    case MediaTrack::AudioKind::kNone:
      return MediaTrack::Kind{""};
  }
}

// static
MediaTrack MediaTrack::CreateVideoTrack(const std::string& id,
                                        VideoKind kind,
                                        const std::string& label,
                                        const std::string& language,
                                        bool enabled,
                                        StreamParser::TrackId stream_id) {
  return MediaTrack{MediaTrack::Type::kVideo,
                    stream_id,
                    MediaTrack::Id{id},
                    VideoKindToString(kind),
                    Label{label},
                    Language{language},
                    enabled,
                    true};
}

// static
MediaTrack MediaTrack::CreateAudioTrack(const std::string& id,
                                        AudioKind kind,
                                        const std::string& label,
                                        const std::string& language,
                                        bool enabled,
                                        StreamParser::TrackId stream_id,
                                        bool exclusive) {
  return MediaTrack{MediaTrack::Type::kAudio,
                    stream_id,
                    MediaTrack::Id{id},
                    AudioKindToString(kind),
                    Label{label},
                    Language{language},
                    enabled,
                    exclusive};
}

MediaTrack::MediaTrack(MediaTrack::Type type,
                       StreamParser::TrackId stream_id,
                       const MediaTrack::Id& track_id,
                       const MediaTrack::Kind& kind,
                       const MediaTrack::Label& label,
                       const MediaTrack::Language& language,
                       bool enabled,
                       bool exclusive)
    : type_(type),
      enabled_(enabled),
      exclusive_(exclusive),
      stream_id_(stream_id),
      track_id_(track_id),
      kind_(kind),
      label_(label),
      language_(language) {}

MediaTrack::MediaTrack(const MediaTrack& track)
    : type_(track.type()),
      enabled_(track.enabled()),
      exclusive_(track.exclusive()),
      stream_id_(track.stream_id()),
      track_id_(track.track_id()),
      kind_(track.kind()),
      label_(track.label()),
      language_(track.language()) {}

}  // namespace media