summaryrefslogtreecommitdiffstats
path: root/media/webm/webm_cluster_parser.h
blob: 2db3755a45f3fc5445066bba22c1b009632551ad (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
// 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 MEDIA_WEBM_WEBM_CLUSTER_PARSER_H_
#define MEDIA_WEBM_WEBM_CLUSTER_PARSER_H_

#include <deque>
#include <string>

#include "base/memory/scoped_ptr.h"
#include "media/base/buffers.h"
#include "media/webm/webm_parser.h"

namespace media {

class WebMClusterParser : public WebMParserClient {
 public:
  typedef std::deque<scoped_refptr<Buffer> > BufferQueue;

  WebMClusterParser(int64 timecode_scale,
                    int audio_track_num,
                    base::TimeDelta audio_default_duration,
                    int video_track_num,
                    base::TimeDelta video_default_duration);
  virtual ~WebMClusterParser();

  // Resets the parser state so it can accept a new cluster.
  void Reset();

  // Parses a WebM cluster element in |buf|.
  //
  // Returns -1 if the parse fails.
  // Returns 0 if more data is needed.
  // Returns the number of bytes parsed on success.
  int Parse(const uint8* buf, int size);

  const BufferQueue& audio_buffers() const { return audio_buffers_; }
  const BufferQueue& video_buffers() const { return video_buffers_; }

 private:
  // WebMParserClient methods.
  virtual WebMParserClient* OnListStart(int id) OVERRIDE;
  virtual bool OnListEnd(int id) OVERRIDE;
  virtual bool OnUInt(int id, int64 val) OVERRIDE;
  virtual bool OnSimpleBlock(int track_num, int timecode, int flags,
                             const uint8* data, int size) OVERRIDE;

  double timecode_multiplier_;  // Multiplier used to convert timecodes into
                                // microseconds.
  int audio_track_num_;
  base::TimeDelta audio_default_duration_;
  int video_track_num_;
  base::TimeDelta  video_default_duration_;

  WebMListParser parser_;

  int64 last_block_timecode_;

  int64 cluster_timecode_;
  BufferQueue audio_buffers_;
  BufferQueue video_buffers_;

  DISALLOW_IMPLICIT_CONSTRUCTORS(WebMClusterParser);
};

}  // namespace media

#endif  // MEDIA_WEBM_WEBM_CLUSTER_PARSER_H_