Pepper_37_C++_interfaces
stream_parser_samsung.h
Go to the documentation of this file.
1 // Copyright 2013 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_CPP_SAMSUNG_STREAM_PARSER_SAMSUNG_H_
6 #define PPAPI_CPP_SAMSUNG_STREAM_PARSER_SAMSUNG_H_
7 
8 #include <vector>
9 
10 #include "ppapi/cpp/instance.h"
11 #include "ppapi/cpp/var.h"
12 #include "ppapi/cpp/dev/buffer_dev.h"
13 #include "ppapi/c/samsung/pp_media_common_samsung.h"
14 #include "ppapi/c/samsung/pp_stream_parser_samsung.h"
15 
16 namespace pp {
17 
18 class CompletionCallback;
19 class InstanceHandle;
20 
21 // Interface allowing NaCl applicaton to implement its own stream demuxer
23  public:
24  // Creates StreamParser_Samsung associated with given |instance|
25  explicit StreamParser_Samsung(Instance* instance);
26 
27  // Destructor
28  virtual ~StreamParser_Samsung() {}
29 
30  // PPB_StreamParser_Samsung API
31 
32  // Used for registering stream parser in Browser. |type| is a MIME type
33  // of stream, to witch parser be registered.
34  int32_t RegisterParser(const char* type, const CompletionCallback& callback);
35 
36  // Indicates completion of parser initialization. |stream_id| is an id of
37  // the stream, that Browser request to parse, if browser request parsing more
38  // that one stream of that type, it allows to recognize that stream.
39  // |init_status| a status of initialization.
40  // If initializations is successful, the |duration| contains stream duration
41  // (in microseconds) if it's possible to recognize it.
42  int32_t InitSegmentReceived(int32_t stream_id, PP_Parser_InitStatus,
43  PP_MicrosecondsDelta duration, const CompletionCallback& callback);
44 
45  // Indicates when new audio configuration have been parsed,
46  // |config| a configuration structure
47  // It's not allowed to deliver new configuration between NewMediaSegment and
48  // EndOfSegment.
49  int32_t NewAudioConfig(int32_t stream_id, const PP_SP_AudioDecoderConfig&,
50  const CompletionCallback& callback);
51 
52  // Indicates when new video configuration have been parsed,
53  // |config| a configuration struct
54  int32_t NewVideoConfig(int32_t stream_id, const PP_SP_VideoDecoderConfig&,
55  const CompletionCallback& callback);
56 
57  // To deliver parsed sample one of below NewBuffers method could be used.
58  // NewBuffers is allowed only between NewMediaSegment and EndOfSegment.
59  // There are four variants of this method, differ used arguments.
60  // For all common are:
61  // |type| indicates type of track, it's enum defined in
62  // pp_stream_parser_samsung.h,
63  // |track_id| it's id of track, useful if is more that one track of that type
64  // |buffer| a buffer with stream data
65  //
66  // Additionally they require:
67  // - passing sample information by using |samples_count| and |samples| (an
68  // array with samples description, or as a |samples| vector.
69  //
70  // Optionally two of them allows to passing encryption information as a pair
71  // of key_id and initialization vector (iv), by passing appropriate arrays
72  // and its sizes or as a vectors.
73 protected:
74  int32_t NewBuffers(int32_t stream_id,
75  PP_ElementaryStream_Type_Samsung type,
76  int32_t track_id, PP_Resource buffer,
77  uint16_t key_id_size, const uint8_t key_id[],
78  uint8_t iv_size, const uint8_t iv[],
79  uint32_t samples_count, const PP_Sample samples[],
80  const CompletionCallback& callback);
81 public:
82  int32_t NewBuffers(int32_t stream_id,
83  PP_ElementaryStream_Type_Samsung type,
84  int32_t track_id, PP_Resource buffer,
85  const std::vector<uint8_t>& key_id, const std::vector<uint8_t>& iv,
86  const std::vector<PP_Sample>& samples,
87  const CompletionCallback& callback);
88  int32_t NewBuffers(int32_t stream_id,
89  PP_ElementaryStream_Type_Samsung type,
90  int32_t track_id, PP_Resource buffer,
91  uint32_t samples_count, const PP_Sample samples[],
92  const CompletionCallback& callback);
93  int32_t NewBuffers(int32_t stream_id,
94  PP_ElementaryStream_Type_Samsung type,
95  int32_t track_id, PP_Resource buffer,
96  const std::vector<PP_Sample>& samples,
97  const CompletionCallback& callback);
98 
99  // Signals the beginning od a new media segment, |timestamp| the earliest
100  // timestamp of all the samples in the segment
101  void NewMediaSegment(int32_t stream_id, PP_MicrosecondsDelta timestamp);
102 
103  // Signals end of segment for given |stream_id|
104  void EndOfSegment(int32_t stream_id);
105 
106  // Method to signal ending of |Parse| from PPP interface (for current buffer).
107  void ParseFinished(int32_t stream_id, PP_ParseResult result);
108 
109  // A new potentially encrypted stream has been parsed. |type| describes type
110  // of the initialization data |init_data| associated with the stream.
111  int32_t NeedKey(int32_t stream_id, const Var& type,
112  uint32_t init_data_size, uint8_t* init_data,
113  const CompletionCallback& callback);
114 
115  // PPP_StreamParser_Samsung API
116 
117  // Initialize the parser. Must be called before any data is passed to Parse().
118  // |stream_type| describe type of stream to parse (should be one of type,
119  // passed in PPB RegisterParser). |stream_id| it's a id of stream to parse.
120  virtual bool Init(int32_t stream_id) = 0;
121 
122  // Called when a seek occurs. This flushes the current parser state and puts
123  // the parser in a state where it can receive data for the new seek point.
124  virtual void Flush(int32_t stream_id) = 0;
125 
126  // Called when there is new data to parse. |data| contains stream to parse.
127  //
128  // Return PP_OK if the parse succeds
129  virtual bool Parse(int32_t stream_id, Buffer_Dev data) = 0;
130 
131  // Called when a parser must be "closed". Used for flushes the current parser
132  // state, and configs.
133  virtual void Close(int32_t stream_id) = 0;
134 
135  private:
136  Instance* instance_;
137 };
138 
139 } // namespace pp
140 
141 #endif // PPAPI_CPP_SAMSUNG_STREAM_PARSER_SAMSUNG_H_
int32_t InitSegmentReceived(int32_t stream_id, PP_Parser_InitStatus, PP_MicrosecondsDelta duration, const CompletionCallback &callback)
void EndOfSegment(int32_t stream_id)
int32_t NewVideoConfig(int32_t stream_id, const PP_SP_VideoDecoderConfig &, const CompletionCallback &callback)
virtual void Flush(int32_t stream_id)=0
int32_t NeedKey(int32_t stream_id, const Var &type, uint32_t init_data_size, uint8_t *init_data, const CompletionCallback &callback)
virtual bool Init(int32_t stream_id)=0
StreamParser_Samsung(Instance *instance)
void NewMediaSegment(int32_t stream_id, PP_MicrosecondsDelta timestamp)
A generic type used for passing data types between the module and the page.
Definition: var.h:21
virtual void Close(int32_t stream_id)=0
int32_t NewBuffers(int32_t stream_id, PP_ElementaryStream_Type_Samsung type, int32_t track_id, PP_Resource buffer, uint16_t key_id_size, const uint8_t key_id[], uint8_t iv_size, const uint8_t iv[], uint32_t samples_count, const PP_Sample samples[], const CompletionCallback &callback)
virtual bool Parse(int32_t stream_id, Buffer_Dev data)=0
int32_t RegisterParser(const char *type, const CompletionCallback &callback)
void ParseFinished(int32_t stream_id, PP_ParseResult result)
int32_t NewAudioConfig(int32_t stream_id, const PP_SP_AudioDecoderConfig &, const CompletionCallback &callback)