OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 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_MP2T_ES_PARSER_H264_H_ |
| 6 #define MEDIA_MP2T_ES_PARSER_H264_H_ |
| 7 |
| 8 #include <list> |
| 9 #include <utility> |
| 10 |
| 11 #include "base/basictypes.h" |
| 12 #include "base/callback.h" |
| 13 #include "base/compiler_specific.h" |
| 14 #include "base/time/time.h" |
| 15 #include "media/base/byte_queue.h" |
| 16 #include "media/base/video_decoder_config.h" |
| 17 #include "media/mp2t/es_parser.h" |
| 18 |
| 19 namespace media { |
| 20 class BitReader; |
| 21 class StreamParserBuffer; |
| 22 } |
| 23 |
| 24 namespace media { |
| 25 namespace mp2t { |
| 26 |
| 27 // Remark: |
| 28 // In this h264 parser, frame splitting is based on AUD nals. |
| 29 // Mpeg2 TS spec: "2.14 Carriage of Rec. ITU-T H.264 | ISO/IEC 14496-10 video" |
| 30 // "Each AVC access unit shall contain an access unit delimiter NAL Unit;" |
| 31 // |
| 32 class EsParserH264 : public EsParser { |
| 33 public: |
| 34 typedef base::Callback<void(const VideoDecoderConfig&)> NewVideoConfigCB; |
| 35 |
| 36 EsParserH264(const NewVideoConfigCB& new_video_config_cb, |
| 37 const EmitBufferCB& emit_buffer_cb); |
| 38 virtual ~EsParserH264(); |
| 39 |
| 40 // EsParser implementation. |
| 41 virtual bool Parse(const uint8* buf, int size, |
| 42 base::TimeDelta pts, |
| 43 base::TimeDelta dts) OVERRIDE; |
| 44 virtual void Flush() OVERRIDE; |
| 45 virtual void Reset() OVERRIDE; |
| 46 |
| 47 private: |
| 48 struct TimingDesc { |
| 49 base::TimeDelta dts; |
| 50 base::TimeDelta pts; |
| 51 }; |
| 52 |
| 53 // H264 parser. |
| 54 // It resumes parsing from byte position |es_pos_|. |
| 55 bool ParseInternal(); |
| 56 |
| 57 // Emit a frame if a frame has been started earlier. |
| 58 void EmitFrameIfNeeded(int next_aud_pos); |
| 59 |
| 60 // Discard |nbytes| of ES from the ES byte queue. |
| 61 void DiscardEs(int nbytes); |
| 62 |
| 63 // Parse a NAL / SPS. |
| 64 // Returns true if successful (compliant bitstream). |
| 65 bool NalParser(const uint8* buf, int size); |
| 66 bool ProcessSPS(const uint8* buf, int size); |
| 67 |
| 68 // Callbacks to pass the stream configuration and the frames. |
| 69 NewVideoConfigCB new_video_config_cb_; |
| 70 EmitBufferCB emit_buffer_cb_; |
| 71 |
| 72 // Bytes of the ES stream that have not been emitted yet. |
| 73 ByteQueue es_byte_queue_; |
| 74 std::list<std::pair<int, TimingDesc> > timing_desc_list_; |
| 75 |
| 76 // H264 parser state. |
| 77 // Note: |current_access_unit_pos_| is pointing to an annexB syncword |
| 78 // while |current_nal_pos_| is pointing to the NAL unit |
| 79 // (i.e. does not include the annexB syncword). |
| 80 int es_pos_; |
| 81 int current_nal_pos_; |
| 82 int current_access_unit_pos_; |
| 83 bool is_key_frame_; |
| 84 |
| 85 // Last video decoder config. |
| 86 VideoDecoderConfig last_video_decoder_config_; |
| 87 }; |
| 88 |
| 89 } // namespace mp2t |
| 90 } // namespace media |
| 91 |
| 92 #endif |
| 93 |
OLD | NEW |