DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs Enumerator
video_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/video_stream_info.h"
8 
9 #include "packager/base/logging.h"
10 #include "packager/base/stl_util.h"
11 #include "packager/base/strings/string_number_conversions.h"
12 #include "packager/base/strings/string_util.h"
13 #include "packager/base/strings/stringprintf.h"
14 #include "packager/media/base/limits.h"
15 
16 namespace edash_packager {
17 namespace media {
18 
19 namespace {
20 std::string VideoCodecToString(VideoCodec video_codec) {
21  switch (video_codec) {
22  case kCodecH264:
23  return "H264";
24  case kCodecVC1:
25  return "VC1";
26  case kCodecMPEG2:
27  return "MPEG2";
28  case kCodecMPEG4:
29  return "MPEG4";
30  case kCodecTheora:
31  return "Theora";
32  case kCodecVP8:
33  return "VP8";
34  case kCodecVP9:
35  return "VP9";
36  default:
37  NOTIMPLEMENTED() << "Unknown Video Codec: " << video_codec;
38  return "UnknownVideoCodec";
39  }
40 }
41 
42 } // namespace
43 
45  uint32_t time_scale,
46  uint64_t duration,
47  VideoCodec codec,
48  const std::string& codec_string,
49  const std::string& language,
50  uint16_t width,
51  uint16_t height,
52  uint32_t pixel_width,
53  uint32_t pixel_height,
54  int16_t trick_play_rate,
55  uint8_t nalu_length_size,
56  const uint8_t* extra_data,
57  size_t extra_data_size,
58  bool is_encrypted)
59  : StreamInfo(kStreamVideo,
60  track_id,
61  time_scale,
62  duration,
63  codec_string,
64  language,
65  extra_data,
66  extra_data_size,
67  is_encrypted),
68  codec_(codec),
69  width_(width),
70  height_(height),
71  pixel_width_(pixel_width),
72  pixel_height_(pixel_height),
73  trick_play_rate_(trick_play_rate),
74  nalu_length_size_(nalu_length_size) {
75 }
76 
77 VideoStreamInfo::~VideoStreamInfo() {}
78 
80  return codec_ != kUnknownVideoCodec &&
81  width_ > 0 && width_ <= limits::kMaxDimension &&
82  height_ > 0 && height_ <= limits::kMaxDimension &&
83  (nalu_length_size_ <= 2 || nalu_length_size_ == 4);
84 }
85 
86 std::string VideoStreamInfo::ToString() const {
87  return base::StringPrintf(
88  "%s codec: %s\n width: %d\n height: %d\n pixel aspect ratio: %d:%d\n "
89  "trick_play_rate: %d\n nalu_length_size: %d\n",
90  StreamInfo::ToString().c_str(), VideoCodecToString(codec_).c_str(),
91  width_, height_, pixel_width_, pixel_height_, trick_play_rate_,
92  nalu_length_size_);
93 }
94 
95 } // namespace media
96 } // namespace edash_packager
std::string ToString() const override
Abstract class holds stream information.
Definition: stream_info.h:26
virtual std::string ToString() const
Definition: stream_info.cc:40
VideoStreamInfo(int track_id, uint32_t time_scale, uint64_t duration, VideoCodec codec, const std::string &codec_string, const std::string &language, uint16_t width, uint16_t height, uint32_t pixel_width, uint32_t pixel_height, int16_t trick_play_rate, uint8_t nalu_length_size, const uint8_t *extra_data, size_t extra_data_size, bool is_encrypted)