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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
// 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 CONTENT_RENDERER_MEDIA_CAPTURE_VIDEO_DECODER_H_
#define CONTENT_RENDERER_MEDIA_CAPTURE_VIDEO_DECODER_H_
#include <deque>
#include "base/time.h"
#include "media/base/demuxer_stream.h"
#include "media/base/filters.h"
#include "media/base/video_frame.h"
#include "media/video/capture/video_capture.h"
namespace base {
class MessageLoopProxy;
}
class VideoCaptureImplManager;
// A filter takes raw frames from video capture engine and passes them to media
// engine as a video decoder filter.
class CaptureVideoDecoder
: public media::VideoDecoder,
public media::VideoCapture::EventHandler {
public:
CaptureVideoDecoder(
base::MessageLoopProxy* message_loop_proxy,
media::VideoCaptureSessionId video_stream_id,
VideoCaptureImplManager* vc_manager,
const media::VideoCapture::VideoCaptureCapability& capability);
virtual ~CaptureVideoDecoder();
// Filter implementation.
virtual void Play(media::FilterCallback* callback) OVERRIDE;
virtual void Seek(base::TimeDelta time,
const media::FilterStatusCB& cb) OVERRIDE;
virtual void Pause(media::FilterCallback* callback) OVERRIDE;
virtual void Stop(media::FilterCallback* callback) OVERRIDE;
// Decoder implementation.
virtual void Initialize(media::DemuxerStream* demuxer_stream,
media::FilterCallback* filter_callback,
media::StatisticsCallback* stat_callback) OVERRIDE;
virtual void ProduceVideoFrame(
scoped_refptr<media::VideoFrame> video_frame) OVERRIDE;
virtual gfx::Size natural_size() OVERRIDE;
// VideoCapture::EventHandler implementation.
virtual void OnStarted(media::VideoCapture* capture) OVERRIDE;
virtual void OnStopped(media::VideoCapture* capture) OVERRIDE;
virtual void OnPaused(media::VideoCapture* capture) OVERRIDE;
virtual void OnError(media::VideoCapture* capture, int error_code) OVERRIDE;
virtual void OnRemoved(media::VideoCapture* capture) OVERRIDE;
virtual void OnBufferReady(
media::VideoCapture* capture,
scoped_refptr<media::VideoCapture::VideoFrameBuffer> buf) OVERRIDE;
virtual void OnDeviceInfoReceived(
media::VideoCapture* capture,
const media::VideoCaptureParams& device_info) OVERRIDE;
private:
friend class CaptureVideoDecoderTest;
enum DecoderState {
kUnInitialized,
kNormal,
kSeeking,
kStopped,
kPaused
};
void PlayOnDecoderThread(media::FilterCallback* callback);
void SeekOnDecoderThread(base::TimeDelta time,
const media::FilterStatusCB& cb);
void PauseOnDecoderThread(media::FilterCallback* callback);
void StopOnDecoderThread(media::FilterCallback* callback);
void InitializeOnDecoderThread(media::DemuxerStream* demuxer_stream,
media::FilterCallback* filter_callback,
media::StatisticsCallback* stat_callback);
void ProduceVideoFrameOnDecoderThread(
scoped_refptr<media::VideoFrame> video_frame);
void OnStoppedOnDecoderThread(media::VideoCapture* capture);
void OnBufferReadyOnDecoderThread(
media::VideoCapture* capture,
scoped_refptr<media::VideoCapture::VideoFrameBuffer> buf);
scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
scoped_refptr<VideoCaptureImplManager> vc_manager_;
media::VideoCapture::VideoCaptureCapability capability_;
DecoderState state_;
std::deque<scoped_refptr<media::VideoFrame> > available_frames_;
media::FilterCallback* pending_stop_cb_;
scoped_ptr<media::StatisticsCallback> statistics_callback_;
media::VideoCaptureSessionId video_stream_id_;
media::VideoCapture* capture_engine_;
base::Time start_time_;
DISALLOW_COPY_AND_ASSIGN(CaptureVideoDecoder);
};
#endif // CONTENT_RENDERER_MEDIA_CAPTURE_VIDEO_DECODER_H_
|