blob: daeee4bb2d11510bb671d955475eb530873a63b2 (
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
// Copyright (c) 2012 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_STREAM_PARSER_H_
#define MEDIA_BASE_STREAM_PARSER_H_
#include <deque>
#include "base/callback_forward.h"
#include "base/memory/ref_counted.h"
#include "base/time.h"
#include "media/base/media_export.h"
namespace media {
class AudioDecoderConfig;
class Buffer;
class VideoDecoderConfig;
// Provides callback methods for StreamParser to report information
// about the media stream.
class MEDIA_EXPORT StreamParserHost {
public:
typedef std::deque<scoped_refptr<Buffer> > BufferQueue;
StreamParserHost();
virtual ~StreamParserHost();
// New audio and/or video decoder configurations were encountered. All audio
// and video buffers after this call will be associated with these
// configurations.
// Returns true if the new configurations are accepted.
// Returns false if the new configurations are not supported and indicates
// that a parsing error should be signalled.
virtual bool OnNewConfigs(const AudioDecoderConfig& audio_config,
const VideoDecoderConfig& video_config) = 0;
// New audio buffers have been received.
virtual bool OnAudioBuffers(const BufferQueue& buffers) = 0;
// New video buffers have been received.
virtual bool OnVideoBuffers(const BufferQueue& buffers) = 0;
private:
DISALLOW_COPY_AND_ASSIGN(StreamParserHost);
};
// Abstract interface for parsing media byte streams.
class MEDIA_EXPORT StreamParser {
public:
StreamParser();
virtual ~StreamParser();
// Indicates completion of parser initialization.
// First parameter - Indicates initialization success. Set to true if
// initialization was successful. False if an error
// occurred.
// Second parameter - Indicates the stream duration. Only contains a valid
// value if the first parameter is true.
typedef base::Callback<void(bool, base::TimeDelta)> InitCB;
// Initialize the parser with necessary callbacks. Must be called before any
// data is passed to Parse(). |init_cb| will be called once enough data has
// been parsed to determine the initial stream configurations, presentation
// start time, and duration.
virtual void Init(const InitCB& init_cb, StreamParserHost* host) = 0;
// Called when a seek occurs. This flushes the current parser state
// and puts the parser in a state where it can receive data for the new seek
// point.
virtual void Flush() = 0;
// Called when there is new data to parse.
//
// Returns true if the parse succeeds.
virtual bool Parse(const uint8* buf, int size) = 0;
private:
DISALLOW_COPY_AND_ASSIGN(StreamParser);
};
} // namespace media
#endif // MEDIA_BASE_STREAM_PARSER_H_
|