summaryrefslogtreecommitdiffstats
path: root/media/base/bitstream_buffer.h
blob: 6ff1c059b98ff595a4a45bdac7302554c1d2c100 (plain)
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
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef MEDIA_BASE_BITSTREAM_BUFFER_H_
#define MEDIA_BASE_BITSTREAM_BUFFER_H_

#include "base/basictypes.h"
#include "base/memory/shared_memory.h"
#include "base/time/time.h"
#include "media/base/decrypt_config.h"
#include "media/base/media_export.h"
#include "media/base/timestamp_constants.h"

namespace media {

// Class for passing bitstream buffers around.  Does not take ownership of the
// data.  This is the media-namespace equivalent of PP_VideoBitstreamBuffer_Dev.
class MEDIA_EXPORT BitstreamBuffer {
 public:
  BitstreamBuffer(int32 id, base::SharedMemoryHandle handle, size_t size);

  BitstreamBuffer(int32 id,
                  base::SharedMemoryHandle handle,
                  size_t size,
                  base::TimeDelta presentation_timestamp);

  ~BitstreamBuffer();

  void SetDecryptConfig(const DecryptConfig& decrypt_config);

  int32 id() const { return id_; }
  base::SharedMemoryHandle handle() const { return handle_; }
  size_t size() const { return size_; }

  // The timestamp is only valid if it's not equal to |media::kNoTimestamp()|.
  base::TimeDelta presentation_timestamp() const {
    return presentation_timestamp_;
  }

  // The following methods come from DecryptConfig.

  const std::string& key_id() const { return key_id_; }
  const std::string& iv() const { return iv_; }
  const std::vector<SubsampleEntry>& subsamples() const { return subsamples_; }

 private:
  int32 id_;
  base::SharedMemoryHandle handle_;
  size_t size_;

  // This is only set when necessary. For example, AndroidVideoDecodeAccelerator
  // needs the timestamp because the underlying decoder may require it to
  // determine the output order.
  base::TimeDelta presentation_timestamp_;

  // The following fields come from DecryptConfig.
  // TODO(timav): Try to DISALLOW_COPY_AND_ASSIGN and include these params as
  // scoped_ptr<DecryptConfig> or explain why copy & assign is needed.

  std::string key_id_;                      // key ID.
  std::string iv_;                          // initialization vector
  std::vector<SubsampleEntry> subsamples_;  // clear/cypher sizes

  // Allow compiler-generated copy & assign constructors.
};

}  // namespace media

#endif  // MEDIA_BASE_BITSTREAM_BUFFER_H_