1/*
2 *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3 *
4 *  Use of this source code is governed by a BSD-style license
5 *  that can be found in the LICENSE file in the root of the source
6 *  tree. An additional intellectual property rights grant can be found
7 *  in the file PATENTS.  All contributing project authors may
8 *  be found in the AUTHORS file in the root of the source tree.
9 */
10
11#ifndef WEBRTC_MODULES_VIDEO_CODING_DECODING_STATE_H_
12#define WEBRTC_MODULES_VIDEO_CODING_DECODING_STATE_H_
13
14#include "webrtc/typedefs.h"
15
16namespace webrtc {
17
18// Forward declarations
19class VCMFrameBuffer;
20class VCMPacket;
21
22class VCMDecodingState {
23 public:
24  VCMDecodingState();
25  ~VCMDecodingState();
26  // Check for old frame
27  bool IsOldFrame(const VCMFrameBuffer* frame) const;
28  // Check for old packet
29  bool IsOldPacket(const VCMPacket* packet) const;
30  // Check for frame continuity based on current decoded state. Use best method
31  // possible, i.e. temporal info, picture ID or sequence number.
32  bool ContinuousFrame(const VCMFrameBuffer* frame) const;
33  void SetState(const VCMFrameBuffer* frame);
34  void CopyFrom(const VCMDecodingState& state);
35  bool UpdateEmptyFrame(const VCMFrameBuffer* frame);
36  // Update the sequence number if the timestamp matches current state and the
37  // sequence number is higher than the current one. This accounts for packets
38  // arriving late.
39  void UpdateOldPacket(const VCMPacket* packet);
40  void SetSeqNum(uint16_t new_seq_num);
41  void Reset();
42  uint32_t time_stamp() const;
43  uint16_t sequence_num() const;
44  // Return true if at initial state.
45  bool in_initial_state() const;
46  // Return true when sync is on - decode all layers.
47  bool full_sync() const;
48
49 private:
50  void UpdateSyncState(const VCMFrameBuffer* frame);
51  // Designated continuity functions
52  bool ContinuousPictureId(int picture_id) const;
53  bool ContinuousSeqNum(uint16_t seq_num) const;
54  bool ContinuousLayer(int temporal_id, int tl0_pic_id) const;
55  bool UsingPictureId(const VCMFrameBuffer* frame) const;
56
57  // Keep state of last decoded frame.
58  // TODO(mikhal/stefan): create designated classes to handle these types.
59  uint16_t    sequence_num_;
60  uint32_t    time_stamp_;
61  int         picture_id_;
62  int         temporal_id_;
63  int         tl0_pic_id_;
64  bool        full_sync_;  // Sync flag when temporal layers are used.
65  bool        in_initial_state_;
66};
67
68}  // namespace webrtc
69
70#endif  // WEBRTC_MODULES_VIDEO_CODING_DECODING_STATE_H_
71