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 MEDIA_BLINK_WEBSOURCEBUFFER_IMPL_H_
6#define MEDIA_BLINK_WEBSOURCEBUFFER_IMPL_H_
7
8#include <string>
9
10#include "base/basictypes.h"
11#include "base/compiler_specific.h"
12#include "base/time/time.h"
13#include "third_party/WebKit/public/platform/WebSourceBuffer.h"
14
15namespace media {
16class ChunkDemuxer;
17
18class WebSourceBufferImpl : public blink::WebSourceBuffer {
19 public:
20  WebSourceBufferImpl(const std::string& id, ChunkDemuxer* demuxer);
21  virtual ~WebSourceBufferImpl();
22
23  // blink::WebSourceBuffer implementation.
24  virtual void setClient(blink::WebSourceBufferClient* client);
25  virtual bool setMode(AppendMode mode);
26  virtual blink::WebTimeRanges buffered();
27  virtual void append(
28      const unsigned char* data,
29      unsigned length,
30      double* timestamp_offset);
31  virtual void abort();
32  virtual void remove(double start, double end);
33  virtual bool setTimestampOffset(double offset);
34  virtual void setAppendWindowStart(double start);
35  virtual void setAppendWindowEnd(double end);
36  virtual void removedFromMediaSource();
37
38 private:
39  // Demuxer callback handler to process an initialization segment received
40  // during an append() call.
41  void InitSegmentReceived();
42
43  std::string id_;
44  ChunkDemuxer* demuxer_;  // Owned by WebMediaPlayerImpl.
45
46  blink::WebSourceBufferClient* client_;
47
48  // Controls the offset applied to timestamps when processing appended media
49  // segments. It is initially 0, which indicates that no offset is being
50  // applied. Both setTimestampOffset() and append() may update this value.
51  base::TimeDelta timestamp_offset_;
52
53  base::TimeDelta append_window_start_;
54  base::TimeDelta append_window_end_;
55
56  DISALLOW_COPY_AND_ASSIGN(WebSourceBufferImpl);
57};
58
59}  // namespace media
60
61#endif  // MEDIA_BLINK_WEBSOURCEBUFFER_IMPL_H_
62