Shaka Packager SDK
stream_info.cc
1 // Copyright 2014 Google Inc. All rights reserved.
2 //
3 // Use of this source code is governed by a BSD-style
4 // license that can be found in the LICENSE file or at
5 // https://developers.google.com/open-source/licenses/bsd
6 
7 #include "packager/media/base/stream_info.h"
8 
9 #include <inttypes.h>
10 
11 #include "packager/base/logging.h"
12 #include "packager/base/strings/stringprintf.h"
13 
14 namespace shaka {
15 namespace media {
16 
17 std::string StreamTypeToString(StreamType type) {
18  switch (type) {
19  case kStreamUnknown:
20  return "Unknown";
21  case kStreamVideo:
22  return "Video";
23  case kStreamAudio:
24  return "Audio";
25  case kStreamText:
26  return "Text";
27  }
28 
29  NOTREACHED() << "Unhandled StreamType with value " << static_cast<int>(type);
30  return "";
31 }
32 
33 StreamInfo::StreamInfo(StreamType stream_type,
34  int track_id,
35  uint32_t time_scale,
36  uint64_t duration,
37  Codec codec,
38  const std::string& codec_string,
39  const uint8_t* codec_config,
40  size_t codec_config_size,
41  const std::string& language,
42  bool is_encrypted)
43  : stream_type_(stream_type),
44  track_id_(track_id),
45  time_scale_(time_scale),
46  duration_(duration),
47  codec_(codec),
48  codec_string_(codec_string),
49  language_(language),
50  is_encrypted_(is_encrypted) {
51  if (codec_config_size > 0) {
52  codec_config_.assign(codec_config, codec_config + codec_config_size);
53  }
54 }
55 
56 StreamInfo::~StreamInfo() {}
57 
58 std::string StreamInfo::ToString() const {
59  return base::StringPrintf(
60  "type: %s\n codec_string: %s\n time_scale: %d\n duration: "
61  "%" PRIu64 " (%.1f seconds)\n is_encrypted: %s\n",
62  (stream_type_ == kStreamAudio ? "Audio" : "Video"), codec_string_.c_str(),
63  time_scale_, duration_, static_cast<double>(duration_) / time_scale_,
64  is_encrypted_ ? "true" : "false");
65 }
66 
67 } // namespace media
68 } // namespace shaka
virtual std::string ToString() const
Definition: stream_info.cc:58
All the methods that are virtual are virtual for mocking.