正在显示
3 个修改的文件
包含
90 行增加
和
45 行删除
| @@ -29,6 +29,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -29,6 +29,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 29 | #include <srs_kernel_log.hpp> | 29 | #include <srs_kernel_log.hpp> |
| 30 | #include <srs_kernel_codec.hpp> | 30 | #include <srs_kernel_codec.hpp> |
| 31 | #include <srs_kernel_stream.hpp> | 31 | #include <srs_kernel_stream.hpp> |
| 32 | +#include <srs_protocol_amf0.hpp> | ||
| 32 | 33 | ||
| 33 | SrsCodecSampleUnit::SrsCodecSampleUnit() | 34 | SrsCodecSampleUnit::SrsCodecSampleUnit() |
| 34 | { | 35 | { |
| @@ -120,6 +121,51 @@ SrsAvcAacCodec::~SrsAvcAacCodec() | @@ -120,6 +121,51 @@ SrsAvcAacCodec::~SrsAvcAacCodec() | ||
| 120 | srs_freep(pictureParameterSetNALUnit); | 121 | srs_freep(pictureParameterSetNALUnit); |
| 121 | } | 122 | } |
| 122 | 123 | ||
| 124 | +int SrsAvcAacCodec::metadata_demux(SrsAmf0Object* metadata) | ||
| 125 | +{ | ||
| 126 | + int ret = ERROR_SUCCESS; | ||
| 127 | + | ||
| 128 | + srs_assert(metadata); | ||
| 129 | + | ||
| 130 | + SrsAmf0Object* obj = metadata; | ||
| 131 | + | ||
| 132 | + // finger out the codec info from metadata if possible. | ||
| 133 | + SrsAmf0Any* prop = NULL; | ||
| 134 | + | ||
| 135 | + if ((prop = obj->get_property("duration")) != NULL && prop->is_number()) { | ||
| 136 | + duration = (int)prop->to_number(); | ||
| 137 | + } | ||
| 138 | + if ((prop = obj->get_property("width")) != NULL && prop->is_number()) { | ||
| 139 | + width = (int)prop->to_number(); | ||
| 140 | + } | ||
| 141 | + if ((prop = obj->get_property("height")) != NULL && prop->is_number()) { | ||
| 142 | + height = (int)prop->to_number(); | ||
| 143 | + } | ||
| 144 | + if ((prop = obj->get_property("framerate")) != NULL && prop->is_number()) { | ||
| 145 | + frame_rate = (int)prop->to_number(); | ||
| 146 | + } | ||
| 147 | + if ((prop = obj->get_property("videocodecid")) != NULL && prop->is_number()) { | ||
| 148 | + video_codec_id = (int)prop->to_number(); | ||
| 149 | + } | ||
| 150 | + if ((prop = obj->get_property("videodatarate")) != NULL && prop->is_number()) { | ||
| 151 | + video_data_rate = (int)(1000 * prop->to_number()); | ||
| 152 | + } | ||
| 153 | + | ||
| 154 | + if ((prop = obj->get_property("audiocodecid")) != NULL && prop->is_number()) { | ||
| 155 | + audio_codec_id = (int)prop->to_number(); | ||
| 156 | + } | ||
| 157 | + if ((prop = obj->get_property("audiodatarate")) != NULL && prop->is_number()) { | ||
| 158 | + audio_data_rate = (int)(1000 * prop->to_number()); | ||
| 159 | + } | ||
| 160 | + | ||
| 161 | + // ignore the following, for each flv/rtmp packet contains them: | ||
| 162 | + // audiosamplerate, sample->sound_rate | ||
| 163 | + // audiosamplesize, sample->sound_size | ||
| 164 | + // stereo, sample->sound_type | ||
| 165 | + | ||
| 166 | + return ret; | ||
| 167 | +} | ||
| 168 | + | ||
| 123 | int SrsAvcAacCodec::audio_aac_demux(char* data, int size, SrsCodecSample* sample) | 169 | int SrsAvcAacCodec::audio_aac_demux(char* data, int size, SrsCodecSample* sample) |
| 124 | { | 170 | { |
| 125 | int ret = ERROR_SUCCESS; | 171 | int ret = ERROR_SUCCESS; |
| @@ -142,6 +188,7 @@ int SrsAvcAacCodec::audio_aac_demux(char* data, int size, SrsCodecSample* sample | @@ -142,6 +188,7 @@ int SrsAvcAacCodec::audio_aac_demux(char* data, int size, SrsCodecSample* sample | ||
| 142 | return ret; | 188 | return ret; |
| 143 | } | 189 | } |
| 144 | 190 | ||
| 191 | + // @see: E.4.2 Audio Tags, video_file_format_spec_v10_1.pdf, page 76 | ||
| 145 | int8_t sound_format = stream->read_1bytes(); | 192 | int8_t sound_format = stream->read_1bytes(); |
| 146 | 193 | ||
| 147 | int8_t sound_type = sound_format & 0x01; | 194 | int8_t sound_type = sound_format & 0x01; |
| @@ -33,6 +33,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -33,6 +33,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 33 | #include <srs_kernel_codec.hpp> | 33 | #include <srs_kernel_codec.hpp> |
| 34 | 34 | ||
| 35 | class SrsStream; | 35 | class SrsStream; |
| 36 | +class SrsAmf0Object; | ||
| 36 | 37 | ||
| 37 | #define SRS_MAX_CODEC_SAMPLE 128 | 38 | #define SRS_MAX_CODEC_SAMPLE 128 |
| 38 | #define _SRS_AAC_SAMPLE_RATE_UNSET 15 | 39 | #define _SRS_AAC_SAMPLE_RATE_UNSET 15 |
| @@ -223,31 +224,59 @@ public: | @@ -223,31 +224,59 @@ public: | ||
| 223 | public: | 224 | public: |
| 224 | /** | 225 | /** |
| 225 | * audio specified | 226 | * audio specified |
| 227 | + * 1.6.2.1 AudioSpecificConfig, in aac-mp4a-format-ISO_IEC_14496-3+2001.pdf, page 33. | ||
| 228 | + * audioObjectType, value defines in 7.1 Profiles, aac-iso-13818-7.pdf, page 40. | ||
| 226 | */ | 229 | */ |
| 227 | - // 1.6.2.1 AudioSpecificConfig, in aac-mp4a-format-ISO_IEC_14496-3+2001.pdf, page 33. | ||
| 228 | - // audioObjectType, value defines in 7.1 Profiles, aac-iso-13818-7.pdf, page 40. | ||
| 229 | u_int8_t aac_profile; | 230 | u_int8_t aac_profile; |
| 230 | - // samplingFrequencyIndex | 231 | + /** |
| 232 | + * samplingFrequencyIndex | ||
| 233 | + */ | ||
| 231 | u_int8_t aac_sample_rate; | 234 | u_int8_t aac_sample_rate; |
| 232 | - // channelConfiguration | 235 | + /** |
| 236 | + * channelConfiguration | ||
| 237 | + */ | ||
| 233 | u_int8_t aac_channels; | 238 | u_int8_t aac_channels; |
| 234 | public: | 239 | public: |
| 235 | - // the avc extra data, the AVC sequence header, | ||
| 236 | - // without the flv codec header, | ||
| 237 | - // @see: ffmpeg, AVCodecContext::extradata | 240 | + /** |
| 241 | + * the avc extra data, the AVC sequence header, | ||
| 242 | + * without the flv codec header, | ||
| 243 | + * @see: ffmpeg, AVCodecContext::extradata | ||
| 244 | + */ | ||
| 238 | int avc_extra_size; | 245 | int avc_extra_size; |
| 239 | char* avc_extra_data; | 246 | char* avc_extra_data; |
| 240 | - // the aac extra data, the AAC sequence header, | ||
| 241 | - // without the flv codec header, | ||
| 242 | - // @see: ffmpeg, AVCodecContext::extradata | 247 | + /** |
| 248 | + * the aac extra data, the AAC sequence header, | ||
| 249 | + * without the flv codec header, | ||
| 250 | + * @see: ffmpeg, AVCodecContext::extradata | ||
| 251 | + */ | ||
| 243 | int aac_extra_size; | 252 | int aac_extra_size; |
| 244 | char* aac_extra_data; | 253 | char* aac_extra_data; |
| 245 | public: | 254 | public: |
| 246 | SrsAvcAacCodec(); | 255 | SrsAvcAacCodec(); |
| 247 | virtual ~SrsAvcAacCodec(); | 256 | virtual ~SrsAvcAacCodec(); |
| 248 | -// the following function used for hls to build the codec info. | 257 | +// the following function used for hls to build the sample and codec. |
| 249 | public: | 258 | public: |
| 259 | + /** | ||
| 260 | + * demux the metadata, to to get the stream info, | ||
| 261 | + * for instance, the width/height, sample rate. | ||
| 262 | + * @param metadata, the metadata amf0 object. assert not NULL. | ||
| 263 | + */ | ||
| 264 | + virtual int metadata_demux(SrsAmf0Object* metadata); | ||
| 265 | + /** | ||
| 266 | + * demux the audio packet in aac codec. | ||
| 267 | + * the packet mux in FLV/RTMP format defined in flv specification. | ||
| 268 | + * demux the audio speicified data(sound_format, sound_size, ...) to sample. | ||
| 269 | + * demux the aac specified data(aac_profile, ...) to codec from sequence header. | ||
| 270 | + * demux the aac raw to sample units. | ||
| 271 | + */ | ||
| 250 | virtual int audio_aac_demux(char* data, int size, SrsCodecSample* sample); | 272 | virtual int audio_aac_demux(char* data, int size, SrsCodecSample* sample); |
| 273 | + /** | ||
| 274 | + * demux the video packet in h.264 codec. | ||
| 275 | + * the packet mux in FLV/RTMP format defined in flv specification. | ||
| 276 | + * demux the video specified data(frame_type, codec_id, ...) to sample. | ||
| 277 | + * demux the h.264 sepcified data(avc_profile, ...) to codec from sequence header. | ||
| 278 | + * demux the h.264 NALUs to sampe units. | ||
| 279 | + */ | ||
| 251 | virtual int video_avc_demux(char* data, int size, SrsCodecSample* sample); | 280 | virtual int video_avc_demux(char* data, int size, SrsCodecSample* sample); |
| 252 | }; | 281 | }; |
| 253 | 282 |
| @@ -1415,46 +1415,15 @@ int SrsHls::on_meta_data(SrsAmf0Object* metadata) | @@ -1415,46 +1415,15 @@ int SrsHls::on_meta_data(SrsAmf0Object* metadata) | ||
| 1415 | return ret; | 1415 | return ret; |
| 1416 | } | 1416 | } |
| 1417 | 1417 | ||
| 1418 | - SrsAmf0Object* obj = metadata; | ||
| 1419 | - if (obj->count() <= 0) { | 1418 | + if (metadata->count() <= 0) { |
| 1420 | srs_trace("no metadata persent, hls ignored it."); | 1419 | srs_trace("no metadata persent, hls ignored it."); |
| 1421 | return ret; | 1420 | return ret; |
| 1422 | } | 1421 | } |
| 1423 | 1422 | ||
| 1424 | - // finger out the codec info from metadata if possible. | ||
| 1425 | - SrsAmf0Any* prop = NULL; | ||
| 1426 | - | ||
| 1427 | - if ((prop = obj->get_property("duration")) != NULL && prop->is_number()) { | ||
| 1428 | - codec->duration = (int)prop->to_number(); | ||
| 1429 | - } | ||
| 1430 | - if ((prop = obj->get_property("width")) != NULL && prop->is_number()) { | ||
| 1431 | - codec->width = (int)prop->to_number(); | ||
| 1432 | - } | ||
| 1433 | - if ((prop = obj->get_property("height")) != NULL && prop->is_number()) { | ||
| 1434 | - codec->height = (int)prop->to_number(); | ||
| 1435 | - } | ||
| 1436 | - if ((prop = obj->get_property("framerate")) != NULL && prop->is_number()) { | ||
| 1437 | - codec->frame_rate = (int)prop->to_number(); | ||
| 1438 | - } | ||
| 1439 | - if ((prop = obj->get_property("videocodecid")) != NULL && prop->is_number()) { | ||
| 1440 | - codec->video_codec_id = (int)prop->to_number(); | ||
| 1441 | - } | ||
| 1442 | - if ((prop = obj->get_property("videodatarate")) != NULL && prop->is_number()) { | ||
| 1443 | - codec->video_data_rate = (int)(1000 * prop->to_number()); | ||
| 1444 | - } | ||
| 1445 | - | ||
| 1446 | - if ((prop = obj->get_property("audiocodecid")) != NULL && prop->is_number()) { | ||
| 1447 | - codec->audio_codec_id = (int)prop->to_number(); | ||
| 1448 | - } | ||
| 1449 | - if ((prop = obj->get_property("audiodatarate")) != NULL && prop->is_number()) { | ||
| 1450 | - codec->audio_data_rate = (int)(1000 * prop->to_number()); | 1423 | + if ((ret = codec->metadata_demux(metadata)) != ERROR_SUCCESS) { |
| 1424 | + return ret; | ||
| 1451 | } | 1425 | } |
| 1452 | 1426 | ||
| 1453 | - // ignore the following, for each flv/rtmp packet contains them: | ||
| 1454 | - // audiosamplerate, sample->sound_rate | ||
| 1455 | - // audiosamplesize, sample->sound_size | ||
| 1456 | - // stereo, sample->sound_type | ||
| 1457 | - | ||
| 1458 | return ret; | 1427 | return ret; |
| 1459 | } | 1428 | } |
| 1460 | 1429 |
-
请 注册 或 登录 后发表评论