Fix some potential after free errors on TestCompletionCallback
[chromium-blink-merge.git] / media / filters / fake_video_decoder.h
blobc82679cbf78bc3998b5a309aea47f6d83b08bf31
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.
5 #ifndef MEDIA_FILTERS_FAKE_VIDEO_DECODER_H_
6 #define MEDIA_FILTERS_FAKE_VIDEO_DECODER_H_
8 #include <list>
10 #include "base/bind.h"
11 #include "base/callback.h"
12 #include "base/callback_helpers.h"
13 #include "base/memory/weak_ptr.h"
14 #include "media/base/callback_holder.h"
15 #include "media/base/decoder_buffer.h"
16 #include "media/base/demuxer_stream.h"
17 #include "media/base/media_export.h"
18 #include "media/base/pipeline_status.h"
19 #include "media/base/video_decoder.h"
20 #include "media/base/video_decoder_config.h"
21 #include "media/base/video_frame.h"
22 #include "ui/gfx/size.h"
24 using base::ResetAndReturn;
26 namespace base {
27 class MessageLoopProxy;
30 namespace media {
32 class MEDIA_EXPORT FakeVideoDecoder : public VideoDecoder {
33 public:
34 // Constructs an object with a decoding delay of |decoding_delay| frames.
35 explicit FakeVideoDecoder(int decoding_delay);
36 virtual ~FakeVideoDecoder();
38 // VideoDecoder implementation.
39 virtual void Initialize(DemuxerStream* stream,
40 const PipelineStatusCB& status_cb,
41 const StatisticsCB& statistics_cb) OVERRIDE;
42 virtual void Read(const ReadCB& read_cb) OVERRIDE;
43 virtual void Reset(const base::Closure& closure) OVERRIDE;
44 virtual void Stop(const base::Closure& closure) OVERRIDE;
46 // Holds the next init/read/reset/stop callback from firing.
47 void HoldNextInit();
48 void HoldNextRead();
49 void HoldNextReset();
50 void HoldNextStop();
52 // Satisfies the pending init/read/reset/stop callback, which must be ready
53 // to fire when these methods are called.
54 void SatisfyInit();
55 void SatisfyRead();
56 void SatisfyReset();
57 void SatisfyStop();
59 private:
60 enum State {
61 UNINITIALIZED,
62 NORMAL
65 void ReadFromDemuxerStream();
67 // Callback for DemuxerStream::Read().
68 void BufferReady(DemuxerStream::Status status,
69 const scoped_refptr<DecoderBuffer>& buffer);
71 void DoReset();
72 void DoStop();
74 scoped_refptr<base::MessageLoopProxy> message_loop_;
75 base::WeakPtrFactory<FakeVideoDecoder> weak_factory_;
76 base::WeakPtr<FakeVideoDecoder> weak_this_;
78 const int decoding_delay_;
80 State state_;
82 StatisticsCB statistics_cb_;
84 CallbackHolder<PipelineStatusCB> init_cb_;
85 CallbackHolder<ReadCB> read_cb_;
86 CallbackHolder<base::Closure> reset_cb_;
87 CallbackHolder<base::Closure> stop_cb_;
89 // Pointer to the demuxer stream that will feed us compressed buffers.
90 DemuxerStream* demuxer_stream_;
92 VideoDecoderConfig current_config_;
94 std::list<scoped_refptr<VideoFrame> > decoded_frames_;
96 DISALLOW_COPY_AND_ASSIGN(FakeVideoDecoder);
99 } // namespace media
101 #endif // MEDIA_FILTERS_FAKE_VIDEO_DECODER_H_