Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / media / formats / mp2t / es_parser_h264.h
index bf4f4cc..dd9184d 100644 (file)
@@ -15,6 +15,7 @@
 #include "base/time/time.h"
 #include "media/base/media_export.h"
 #include "media/base/video_decoder_config.h"
+#include "media/formats/mp2t/es_adapter_video.h"
 #include "media/formats/mp2t/es_parser.h"
 
 namespace media {
@@ -26,12 +27,16 @@ class OffsetByteQueue;
 namespace media {
 namespace mp2t {
 
-// Remark:
-// In this h264 parser, frame splitting is based on AUD nals.
+// A few remarks:
+// In this h264 parser, frame splitting is based on AUD nals.
 // Mpeg2 TS spec: "2.14 Carriage of Rec. ITU-T H.264 | ISO/IEC 14496-10 video"
 // "Each AVC access unit shall contain an access unit delimiter NAL Unit;"
+// - PES packets do not necessarily map to an H264 access unit although the HLS
+// recommendation is to use one PES for each access unit. In this parser,
+// we handle the general case and do not make any assumption about the access
+// unit organization within PES packets.
 //
-class MEDIA_EXPORT EsParserH264 : NON_EXPORTED_BASE(public EsParser) {
+class MEDIA_EXPORT EsParserH264 : public EsParser {
  public:
   typedef base::Callback<void(const VideoDecoderConfig&)> NewVideoConfigCB;
 
@@ -40,17 +45,12 @@ class MEDIA_EXPORT EsParserH264 : NON_EXPORTED_BASE(public EsParser) {
   virtual ~EsParserH264();
 
   // EsParser implementation.
-  virtual bool Parse(const uint8* buf, int size,
-                     base::TimeDelta pts,
-                     base::TimeDelta dts) OVERRIDE;
   virtual void Flush() OVERRIDE;
-  virtual void Reset() OVERRIDE;
 
  private:
-  struct TimingDesc {
-    base::TimeDelta dts;
-    base::TimeDelta pts;
-  };
+  // EsParser implementation.
+  virtual bool ParseFromEsQueue() OVERRIDE;
+  virtual void ResetInternal() OVERRIDE;
 
   // Find the AUD located at or after |*stream_pos|.
   // Return true if an AUD is found.
@@ -59,10 +59,6 @@ class MEDIA_EXPORT EsParserH264 : NON_EXPORTED_BASE(public EsParser) {
   // of the start code parser.
   bool FindAUD(int64* stream_pos);
 
-  // Resumes the H264 ES parsing.
-  // Return true if successful.
-  bool ParseInternal();
-
   // Emit a frame whose position in the ES queue starts at |access_unit_pos|.
   // Returns true if successful, false if no PTS is available for the frame.
   bool EmitFrame(int64 access_unit_pos, int access_unit_size,
@@ -72,13 +68,7 @@ class MEDIA_EXPORT EsParserH264 : NON_EXPORTED_BASE(public EsParser) {
   // Return true if successful.
   bool UpdateVideoDecoderConfig(const H264SPS* sps);
 
-  // Callbacks to pass the stream configuration and the frames.
-  NewVideoConfigCB new_video_config_cb_;
-  EmitBufferCB emit_buffer_cb_;
-
-  // Bytes of the ES stream that have not been emitted yet.
-  scoped_ptr<media::OffsetByteQueue> es_queue_;
-  std::list<std::pair<int64, TimingDesc> > timing_desc_list_;
+  EsAdapterVideo es_adapter_;
 
   // H264 parser state.
   // - |current_access_unit_pos_| is pointing to an annexB syncword
@@ -89,10 +79,11 @@ class MEDIA_EXPORT EsParserH264 : NON_EXPORTED_BASE(public EsParser) {
 
   // Last video decoder config.
   VideoDecoderConfig last_video_decoder_config_;
+
+  DISALLOW_COPY_AND_ASSIGN(EsParserH264);
 };
 
 }  // namespace mp2t
 }  // namespace media
 
 #endif
-