DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs
media_sample.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/media_sample.h"
8 
9 #include <inttypes.h>
10 
11 #include "packager/base/logging.h"
12 #include "packager/base/strings/stringprintf.h"
13 
14 namespace edash_packager {
15 namespace media {
16 
17 MediaSample::MediaSample(const uint8_t* data,
18  size_t size,
19  const uint8_t* side_data,
20  size_t side_data_size,
21  bool is_key_frame)
22  : dts_(0),
23  pts_(0),
24  duration_(0),
25  is_key_frame_(is_key_frame),
26  is_encrypted_(false) {
27  if (!data) {
28  CHECK_EQ(size, 0u);
29  CHECK(!side_data);
30  return;
31  }
32 
33  data_.assign(data, data + size);
34  if (side_data)
35  side_data_.assign(side_data, side_data + side_data_size);
36 }
37 
38 MediaSample::MediaSample() : dts_(0),
39  pts_(0),
40  duration_(0),
41  is_key_frame_(false),
42  is_encrypted_(false) {}
43 
44 MediaSample::~MediaSample() {}
45 
46 // static
47 scoped_refptr<MediaSample> MediaSample::CopyFrom(const uint8_t* data,
48  size_t data_size,
49  bool is_key_frame) {
50  // If you hit this CHECK you likely have a bug in a demuxer. Go fix it.
51  CHECK(data);
52  return make_scoped_refptr(
53  new MediaSample(data, data_size, NULL, 0u, is_key_frame));
54 }
55 
56 // static
57 scoped_refptr<MediaSample> MediaSample::CopyFrom(const uint8_t* data,
58  size_t data_size,
59  const uint8_t* side_data,
60  size_t side_data_size,
61  bool is_key_frame) {
62  // If you hit this CHECK you likely have a bug in a demuxer. Go fix it.
63  CHECK(data);
64  return make_scoped_refptr(new MediaSample(
65  data, data_size, side_data, side_data_size, is_key_frame));
66 }
67 
68 // static
69 scoped_refptr<MediaSample> MediaSample::CreateEmptyMediaSample() {
70  MediaSample* media_sample = new MediaSample();
71  return make_scoped_refptr(media_sample);
72 }
73 
74 // static
75 scoped_refptr<MediaSample> MediaSample::CreateEOSBuffer() {
76  return make_scoped_refptr(new MediaSample(NULL, 0, NULL, 0, false));
77 }
78 
79 std::string MediaSample::ToString() const {
80  if (end_of_stream())
81  return "End of stream sample\n";
82  return base::StringPrintf(
83  "dts: %" PRId64 "\n pts: %" PRId64 "\n duration: %" PRId64 "\n "
84  "is_key_frame: %s\n size: %zu\n side_data_size: %zu\n",
85  dts_,
86  pts_,
87  duration_,
88  is_key_frame_ ? "true" : "false",
89  data_.size(),
90  side_data_.size());
91 }
92 
93 } // namespace media
94 } // namespace edash_packager
static scoped_refptr< MediaSample > CopyFrom(const uint8_t *data, size_t size, bool is_key_frame)
Definition: media_sample.cc:47
static scoped_refptr< MediaSample > CreateEOSBuffer()
Definition: media_sample.cc:75
static scoped_refptr< MediaSample > CreateEmptyMediaSample()
Create a MediaSample object with default members.
Definition: media_sample.cc:69
Class to hold a media sample.
Definition: media_sample.h:22