winlin

refine hls avc/aac codec, move metadata to it.

... ... @@ -29,6 +29,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_kernel_log.hpp>
#include <srs_kernel_codec.hpp>
#include <srs_kernel_stream.hpp>
#include <srs_protocol_amf0.hpp>
SrsCodecSampleUnit::SrsCodecSampleUnit()
{
... ... @@ -120,6 +121,51 @@ SrsAvcAacCodec::~SrsAvcAacCodec()
srs_freep(pictureParameterSetNALUnit);
}
int SrsAvcAacCodec::metadata_demux(SrsAmf0Object* metadata)
{
int ret = ERROR_SUCCESS;
srs_assert(metadata);
SrsAmf0Object* obj = metadata;
// finger out the codec info from metadata if possible.
SrsAmf0Any* prop = NULL;
if ((prop = obj->get_property("duration")) != NULL && prop->is_number()) {
duration = (int)prop->to_number();
}
if ((prop = obj->get_property("width")) != NULL && prop->is_number()) {
width = (int)prop->to_number();
}
if ((prop = obj->get_property("height")) != NULL && prop->is_number()) {
height = (int)prop->to_number();
}
if ((prop = obj->get_property("framerate")) != NULL && prop->is_number()) {
frame_rate = (int)prop->to_number();
}
if ((prop = obj->get_property("videocodecid")) != NULL && prop->is_number()) {
video_codec_id = (int)prop->to_number();
}
if ((prop = obj->get_property("videodatarate")) != NULL && prop->is_number()) {
video_data_rate = (int)(1000 * prop->to_number());
}
if ((prop = obj->get_property("audiocodecid")) != NULL && prop->is_number()) {
audio_codec_id = (int)prop->to_number();
}
if ((prop = obj->get_property("audiodatarate")) != NULL && prop->is_number()) {
audio_data_rate = (int)(1000 * prop->to_number());
}
// ignore the following, for each flv/rtmp packet contains them:
// audiosamplerate, sample->sound_rate
// audiosamplesize, sample->sound_size
// stereo, sample->sound_type
return ret;
}
int SrsAvcAacCodec::audio_aac_demux(char* data, int size, SrsCodecSample* sample)
{
int ret = ERROR_SUCCESS;
... ... @@ -142,6 +188,7 @@ int SrsAvcAacCodec::audio_aac_demux(char* data, int size, SrsCodecSample* sample
return ret;
}
// @see: E.4.2 Audio Tags, video_file_format_spec_v10_1.pdf, page 76
int8_t sound_format = stream->read_1bytes();
int8_t sound_type = sound_format & 0x01;
... ...
... ... @@ -33,6 +33,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_kernel_codec.hpp>
class SrsStream;
class SrsAmf0Object;
#define SRS_MAX_CODEC_SAMPLE 128
#define _SRS_AAC_SAMPLE_RATE_UNSET 15
... ... @@ -223,31 +224,59 @@ public:
public:
/**
* audio specified
* 1.6.2.1 AudioSpecificConfig, in aac-mp4a-format-ISO_IEC_14496-3+2001.pdf, page 33.
* audioObjectType, value defines in 7.1 Profiles, aac-iso-13818-7.pdf, page 40.
*/
// 1.6.2.1 AudioSpecificConfig, in aac-mp4a-format-ISO_IEC_14496-3+2001.pdf, page 33.
// audioObjectType, value defines in 7.1 Profiles, aac-iso-13818-7.pdf, page 40.
u_int8_t aac_profile;
// samplingFrequencyIndex
/**
* samplingFrequencyIndex
*/
u_int8_t aac_sample_rate;
// channelConfiguration
/**
* channelConfiguration
*/
u_int8_t aac_channels;
public:
// the avc extra data, the AVC sequence header,
// without the flv codec header,
// @see: ffmpeg, AVCodecContext::extradata
/**
* the avc extra data, the AVC sequence header,
* without the flv codec header,
* @see: ffmpeg, AVCodecContext::extradata
*/
int avc_extra_size;
char* avc_extra_data;
// the aac extra data, the AAC sequence header,
// without the flv codec header,
// @see: ffmpeg, AVCodecContext::extradata
/**
* the aac extra data, the AAC sequence header,
* without the flv codec header,
* @see: ffmpeg, AVCodecContext::extradata
*/
int aac_extra_size;
char* aac_extra_data;
public:
SrsAvcAacCodec();
virtual ~SrsAvcAacCodec();
// the following function used for hls to build the codec info.
// the following function used for hls to build the sample and codec.
public:
/**
* demux the metadata, to to get the stream info,
* for instance, the width/height, sample rate.
* @param metadata, the metadata amf0 object. assert not NULL.
*/
virtual int metadata_demux(SrsAmf0Object* metadata);
/**
* demux the audio packet in aac codec.
* the packet mux in FLV/RTMP format defined in flv specification.
* demux the audio speicified data(sound_format, sound_size, ...) to sample.
* demux the aac specified data(aac_profile, ...) to codec from sequence header.
* demux the aac raw to sample units.
*/
virtual int audio_aac_demux(char* data, int size, SrsCodecSample* sample);
/**
* demux the video packet in h.264 codec.
* the packet mux in FLV/RTMP format defined in flv specification.
* demux the video specified data(frame_type, codec_id, ...) to sample.
* demux the h.264 sepcified data(avc_profile, ...) to codec from sequence header.
* demux the h.264 NALUs to sampe units.
*/
virtual int video_avc_demux(char* data, int size, SrsCodecSample* sample);
};
... ...
... ... @@ -1415,46 +1415,15 @@ int SrsHls::on_meta_data(SrsAmf0Object* metadata)
return ret;
}
SrsAmf0Object* obj = metadata;
if (obj->count() <= 0) {
if (metadata->count() <= 0) {
srs_trace("no metadata persent, hls ignored it.");
return ret;
}
// finger out the codec info from metadata if possible.
SrsAmf0Any* prop = NULL;
if ((prop = obj->get_property("duration")) != NULL && prop->is_number()) {
codec->duration = (int)prop->to_number();
}
if ((prop = obj->get_property("width")) != NULL && prop->is_number()) {
codec->width = (int)prop->to_number();
}
if ((prop = obj->get_property("height")) != NULL && prop->is_number()) {
codec->height = (int)prop->to_number();
}
if ((prop = obj->get_property("framerate")) != NULL && prop->is_number()) {
codec->frame_rate = (int)prop->to_number();
}
if ((prop = obj->get_property("videocodecid")) != NULL && prop->is_number()) {
codec->video_codec_id = (int)prop->to_number();
}
if ((prop = obj->get_property("videodatarate")) != NULL && prop->is_number()) {
codec->video_data_rate = (int)(1000 * prop->to_number());
}
if ((prop = obj->get_property("audiocodecid")) != NULL && prop->is_number()) {
codec->audio_codec_id = (int)prop->to_number();
}
if ((prop = obj->get_property("audiodatarate")) != NULL && prop->is_number()) {
codec->audio_data_rate = (int)(1000 * prop->to_number());
if ((ret = codec->metadata_demux(metadata)) != ERROR_SUCCESS) {
return ret;
}
// ignore the following, for each flv/rtmp packet contains them:
// audiosamplerate, sample->sound_rate
// audiosamplesize, sample->sound_size
// stereo, sample->sound_type
return ret;
}
... ...