1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef PPAPI_SHARED_IMPL_MEDIA_STREAM_BUFFER_H_
6 #define PPAPI_SHARED_IMPL_MEDIA_STREAM_BUFFER_H_
7 
8 #include <stdint.h>
9 
10 #include "ppapi/c/ppb_audio_buffer.h"
11 #include "ppapi/c/ppb_video_frame.h"
12 
13 namespace ppapi {
14 
15 union MediaStreamBuffer {
16   enum Type {
17     TYPE_UNKNOWN = 0,
18     TYPE_AUDIO = 1,
19     TYPE_VIDEO = 2,
20     TYPE_BITSTREAM = 3
21   };
22 
23   struct Header {
24     Type type;
25     uint32_t size;
26   };
27 
28   struct Audio {
29     Header header;
30     PP_TimeDelta timestamp;
31     PP_AudioBuffer_SampleRate sample_rate;
32     uint32_t number_of_channels;
33     uint32_t number_of_samples;
34     uint32_t data_size;
35     // Uses 8 bytes to make sure the Audio struct has consistent size between
36     // NaCl code and renderer code.
37     uint8_t data[8];
38   };
39 
40   struct Video {
41     Header header;
42     PP_TimeDelta timestamp;
43     PP_VideoFrame_Format format;
44     PP_Size size;
45     uint32_t data_size;
46     // Uses 8 bytes to make sure the Video struct has consistent size between
47     // NaCl code and renderer code.
48     uint8_t data[8];
49   };
50 
51   struct Bitstream {
52     Header header;
53     uint32_t data_size;
54     // Uses 8 bytes to make sure the Bitstream struct has consistent size
55     // between NaCl code and renderer code.
56     uint8_t data[8];
57   };
58 
59   // Because these structs are written and read in shared memory, we need
60   // the size and alighment to be consistent between NaCl and its host trusted
61   // platform.
62   PP_COMPILE_ASSERT_SIZE_IN_BYTES(Header, 8);
63   PP_COMPILE_ASSERT_SIZE_IN_BYTES(Audio, 40);
64   PP_COMPILE_ASSERT_SIZE_IN_BYTES(Video, 40);
65   PP_COMPILE_ASSERT_SIZE_IN_BYTES(Bitstream, 20);
66 
67   Header header;
68   Video video;
69   Audio audio;
70   Bitstream bitstream;
71 };
72 
73 }  // namespace ppapi
74 
75 #endif  // PPAPI_SHARED_IMPL_MEDIA_STREAM_BUFFER_H_
76