Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(298)

Side by Side Diff: media/base/stream_parser.h

Issue 10134066: Replace StreamParserHost interface with callbacks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Make callbacks hold unretained references. Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | media/base/stream_parser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MEDIA_BASE_STREAM_PARSER_H_ 5 #ifndef MEDIA_BASE_STREAM_PARSER_H_
6 #define MEDIA_BASE_STREAM_PARSER_H_ 6 #define MEDIA_BASE_STREAM_PARSER_H_
7 7
8 #include <deque> 8 #include <deque>
9 9
10 #include "base/callback_forward.h" 10 #include "base/callback_forward.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/time.h" 12 #include "base/time.h"
13 #include "media/base/media_export.h" 13 #include "media/base/media_export.h"
14 14
15 namespace media { 15 namespace media {
16 16
17 class AudioDecoderConfig; 17 class AudioDecoderConfig;
18 class Buffer; 18 class Buffer;
19 class VideoDecoderConfig; 19 class VideoDecoderConfig;
20 20
21 // Provides callback methods for StreamParser to report information
22 // about the media stream.
23 class MEDIA_EXPORT StreamParserHost {
24 public:
25 typedef std::deque<scoped_refptr<Buffer> > BufferQueue;
26
27 StreamParserHost();
28 virtual ~StreamParserHost();
29
30 // New audio and/or video decoder configurations were encountered. All audio
31 // and video buffers after this call will be associated with these
32 // configurations.
33 // Returns true if the new configurations are accepted.
34 // Returns false if the new configurations are not supported and indicates
35 // that a parsing error should be signalled.
36 virtual bool OnNewConfigs(const AudioDecoderConfig& audio_config,
37 const VideoDecoderConfig& video_config) = 0;
38
39 // New audio buffers have been received.
40 virtual bool OnAudioBuffers(const BufferQueue& buffers) = 0;
41
42 // New video buffers have been received.
43 virtual bool OnVideoBuffers(const BufferQueue& buffers) = 0;
44
45 private:
46 DISALLOW_COPY_AND_ASSIGN(StreamParserHost);
47 };
48
49 // Abstract interface for parsing media byte streams. 21 // Abstract interface for parsing media byte streams.
50 class MEDIA_EXPORT StreamParser { 22 class MEDIA_EXPORT StreamParser {
51 public: 23 public:
24 typedef std::deque<scoped_refptr<Buffer> > BufferQueue;
25
52 StreamParser(); 26 StreamParser();
53 virtual ~StreamParser(); 27 virtual ~StreamParser();
54 28
55 // Indicates completion of parser initialization. 29 // Indicates completion of parser initialization.
56 // First parameter - Indicates initialization success. Set to true if 30 // First parameter - Indicates initialization success. Set to true if
57 // initialization was successful. False if an error 31 // initialization was successful. False if an error
58 // occurred. 32 // occurred.
59 // Second parameter - Indicates the stream duration. Only contains a valid 33 // Second parameter - Indicates the stream duration. Only contains a valid
60 // value if the first parameter is true. 34 // value if the first parameter is true.
61 typedef base::Callback<void(bool, base::TimeDelta)> InitCB; 35 typedef base::Callback<void(bool, base::TimeDelta)> InitCB;
62 36
37 // Indicates when new stream configurations have been parsed.
38 // First parameter - The new audio configuration. If the config is not valid
39 // then it means that there isn't an audio stream.
40 // Second parameter - The new video configuration. If the config is not valid
41 // then it means that there isn't an audio stream.
42 // Return value - True if the new configurations are accepted.
43 // False if the new configurations are not supported
44 // and indicates that a parsing error should be signalled.
45 typedef base::Callback<bool(const AudioDecoderConfig&,
46 const VideoDecoderConfig&)> NewConfigCB;
47
48 // New stream buffers have been parsed.
49 // First parameter - A queue of newly parsed buffers.
50 // Return value - True indicates that the buffers are accepted.
51 // False if something was wrong with the buffers and a parsing
52 // error should be signalled.
53 typedef base::Callback<bool(const BufferQueue&)> NewBuffersCB;
54
55
63 // Initialize the parser with necessary callbacks. Must be called before any 56 // Initialize the parser with necessary callbacks. Must be called before any
64 // data is passed to Parse(). |init_cb| will be called once enough data has 57 // data is passed to Parse(). |init_cb| will be called once enough data has
65 // been parsed to determine the initial stream configurations, presentation 58 // been parsed to determine the initial stream configurations, presentation
66 // start time, and duration. 59 // start time, and duration.
67 virtual void Init(const InitCB& init_cb, StreamParserHost* host) = 0; 60 virtual void Init(const InitCB& init_cb,
61 const NewConfigCB& config_cb,
62 const NewBuffersCB& audio_cb,
63 const NewBuffersCB& video_cb) = 0;
68 64
69 // Called when a seek occurs. This flushes the current parser state 65 // Called when a seek occurs. This flushes the current parser state
70 // and puts the parser in a state where it can receive data for the new seek 66 // and puts the parser in a state where it can receive data for the new seek
71 // point. 67 // point.
72 virtual void Flush() = 0; 68 virtual void Flush() = 0;
73 69
74 // Called when there is new data to parse. 70 // Called when there is new data to parse.
75 // 71 //
76 // Returns true if the parse succeeds. 72 // Returns true if the parse succeeds.
77 virtual bool Parse(const uint8* buf, int size) = 0; 73 virtual bool Parse(const uint8* buf, int size) = 0;
78 74
79 private: 75 private:
80 DISALLOW_COPY_AND_ASSIGN(StreamParser); 76 DISALLOW_COPY_AND_ASSIGN(StreamParser);
81 }; 77 };
82 78
83 } // namespace media 79 } // namespace media
84 80
85 #endif // MEDIA_BASE_STREAM_PARSER_H_ 81 #endif // MEDIA_BASE_STREAM_PARSER_H_
OLDNEW
« no previous file with comments | « no previous file | media/base/stream_parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698