1// Copyright 2014 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_FORMATS_MPEG_MPEG1_AUDIO_STREAM_PARSER_H_ 6#define MEDIA_FORMATS_MPEG_MPEG1_AUDIO_STREAM_PARSER_H_ 7 8#include "base/basictypes.h" 9#include "media/base/media_export.h" 10#include "media/formats/mpeg/mpeg_audio_stream_parser_base.h" 11 12namespace media { 13 14// MPEG1AudioStreamParser handles MPEG-1 audio streams (ISO/IEC 11172-3) 15// as well as the following extensions: 16// - MPEG-2 audio (ISO/IEC 13818-3), 17// - and MPEG2.5 (not an ISO standard). 18class MEDIA_EXPORT MPEG1AudioStreamParser : public MPEGAudioStreamParserBase { 19 public: 20 // Size of an MPEG-1 frame header in bytes. 21 enum { 22 kHeaderSize = 4, 23 }; 24 25 // Versions and layers as defined in ISO/IEC 11172-3. 26 enum Version { 27 kVersion1 = 3, 28 kVersion2 = 2, 29 kVersionReserved = 1, 30 kVersion2_5 = 0, 31 }; 32 33 enum Layer { 34 kLayer1 = 3, 35 kLayer2 = 2, 36 kLayer3 = 1, 37 kLayerReserved = 0, 38 }; 39 40 struct Header { 41 Version version; 42 43 // Layer as defined in ISO/IEC 11172-3 bitstream specification. 44 Layer layer; 45 46 // Frame size in bytes. 47 int frame_size; 48 49 // Sample frequency. 50 int sample_rate; 51 52 // Channel mode as defined in ISO/IEC 11172-3 bitstream specification. 53 int channel_mode; 54 55 // Channel layout. 56 ChannelLayout channel_layout; 57 58 // Number of samples per frame. 59 int sample_count; 60 }; 61 62 // Parses the header starting at |data|. 63 // Assumption: size of array |data| should be at least |kHeaderSize|. 64 // Returns false if the header is not valid. 65 static bool ParseHeader( 66 const LogCB& log_cb, 67 const uint8* data, 68 Header* header); 69 70 MPEG1AudioStreamParser(); 71 virtual ~MPEG1AudioStreamParser(); 72 73 private: 74 // MPEGAudioStreamParserBase overrides. 75 virtual int ParseFrameHeader(const uint8* data, 76 int size, 77 int* frame_size, 78 int* sample_rate, 79 ChannelLayout* channel_layout, 80 int* sample_count, 81 bool* metadata_frame) const OVERRIDE; 82 83 DISALLOW_COPY_AND_ASSIGN(MPEG1AudioStreamParser); 84}; 85 86} // namespace media 87 88#endif // MEDIA_FORMATS_MPEG_MPEG1_AUDIO_STREAM_PARSER_H_ 89