Skip to content

Commit

Permalink
for #738, fix the audio sample offset error.
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Feb 5, 2017
1 parent 733252d commit 4fe79a1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
6 changes: 5 additions & 1 deletion trunk/src/kernel/srs_kernel_mp4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3319,19 +3319,23 @@ int SrsMp4SampleManager::load_trak(map<uint64_t, SrsMp4Sample*>& tses, SrsCodecF

// For each chunk offset.
for (uint32_t ci = 0; ci < stco->entry_count; ci++) {
// The sample offset relative in chunk.
uint32_t sample_relative_offset = 0;

// Find how many samples from stsc.
SrsMp4StscEntry* stsc_entry = stsc->on_chunk(ci);
for (uint32_t i = 0; i < stsc_entry->samples_per_chunk; i++) {
SrsMp4Sample* sample = new SrsMp4Sample();
sample->type = tt;
sample->index = (previous? previous->index+1:0);
sample->tbn = mdhd->timescale;
sample->offset = stco->entries[ci] + sample_relative_offset;

uint32_t sample_size = 0;
if ((ret = stsz->get_sample_size(sample->index, &sample_size)) != ERROR_SUCCESS) {
return ret;
}
sample->offset = stco->entries[ci] + sample_size * i;
sample_relative_offset += sample_size;

SrsMp4SttsEntry* stts_entry = NULL;
if ((ret = stts->on_sample(sample->index, &stts_entry)) != ERROR_SUCCESS) {
Expand Down
31 changes: 21 additions & 10 deletions trunk/src/libs/srs_librtmp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2602,33 +2602,44 @@ int srs_human_print_rtmp_packet4(char type, uint32_t timestamp, char* data, int
ndiff = (int)(srs_utils_time_ms() - pre_now);
}

char sbytes[40];
if (true) {
int nb = srs_min(8, size);
int p = 0;
for (int i = 0; i < nb; i++) {
p += snprintf(sbytes+p, 40-p, "0x%02x ", (uint8_t)data[i]);
}
}

uint32_t pts;
if (srs_utils_parse_timestamp(timestamp, type, data, size, &pts) != 0) {
srs_human_trace("Rtmp packet id=%"PRId64"/%.1f/%.1f, type=%s, dts=%d, ndiff=%d, diff=%d, size=%d, DecodeError",
nb_packets, pi, gfps, srs_human_flv_tag_type2string(type), timestamp, ndiff, diff, size
srs_human_trace("Rtmp packet id=%"PRId64"/%.1f/%.1f, type=%s, dts=%d, ndiff=%d, diff=%d, size=%d, DecodeError, (%s)",
nb_packets, pi, gfps, srs_human_flv_tag_type2string(type), timestamp, ndiff, diff, size, sbytes
);
return ret;
}

if (type == SRS_RTMP_TYPE_VIDEO) {
srs_human_trace("Video packet id=%"PRId64"/%.1f/%.1f, type=%s, dts=%d, pts=%d, ndiff=%d, diff=%d, size=%d, %s(%s,%s)",
srs_human_trace("Video packet id=%"PRId64"/%.1f/%.1f, type=%s, dts=%d, pts=%d, ndiff=%d, diff=%d, size=%d, %s(%s,%s), (%s)",
nb_packets, pi, gfps, srs_human_flv_tag_type2string(type), timestamp, pts, ndiff, diff, size,
srs_human_flv_video_codec_id2string(srs_utils_flv_video_codec_id(data, size)),
srs_human_flv_video_avc_packet_type2string(srs_utils_flv_video_avc_packet_type(data, size)),
srs_human_flv_video_frame_type2string(srs_utils_flv_video_frame_type(data, size))
srs_human_flv_video_frame_type2string(srs_utils_flv_video_frame_type(data, size)),
sbytes
);
} else if (type == SRS_RTMP_TYPE_AUDIO) {
srs_human_trace("Audio packet id=%"PRId64"/%.1f/%.1f, type=%s, dts=%d, pts=%d, ndiff=%d, diff=%d, size=%d, %s(%s,%s,%s,%s)",
srs_human_trace("Audio packet id=%"PRId64"/%.1f/%.1f, type=%s, dts=%d, pts=%d, ndiff=%d, diff=%d, size=%d, %s(%s,%s,%s,%s), (%s)",
nb_packets, pi, gfps, srs_human_flv_tag_type2string(type), timestamp, pts, ndiff, diff, size,
srs_human_flv_audio_sound_format2string(srs_utils_flv_audio_sound_format(data, size)),
srs_human_flv_audio_sound_rate2string(srs_utils_flv_audio_sound_rate(data, size)),
srs_human_flv_audio_sound_size2string(srs_utils_flv_audio_sound_size(data, size)),
srs_human_flv_audio_sound_type2string(srs_utils_flv_audio_sound_type(data, size)),
srs_human_flv_audio_aac_packet_type2string(srs_utils_flv_audio_aac_packet_type(data, size))
srs_human_flv_audio_aac_packet_type2string(srs_utils_flv_audio_aac_packet_type(data, size)),
sbytes
);
} else if (type == SRS_RTMP_TYPE_SCRIPT) {
srs_human_trace("Data packet id=%"PRId64"/%.1f/%.1f, type=%s, time=%d, ndiff=%d, diff=%d, size=%d",
nb_packets, pi, gfps, srs_human_flv_tag_type2string(type), timestamp, ndiff, diff, size);
srs_human_trace("Data packet id=%"PRId64"/%.1f/%.1f, type=%s, time=%d, ndiff=%d, diff=%d, size=%d, (%s)",
nb_packets, pi, gfps, srs_human_flv_tag_type2string(type), timestamp, ndiff, diff, size, sbytes);
int nparsed = 0;
while (nparsed < size) {
int nb_parsed_this = 0;
Expand All @@ -2644,8 +2655,8 @@ int srs_human_print_rtmp_packet4(char type, uint32_t timestamp, char* data, int
srs_freepa(amf0_str);
}
} else {
srs_human_trace("Rtmp packet id=%"PRId64"/%.1f/%.1f, type=%#x, dts=%d, pts=%d, ndiff=%d, diff=%d, size=%d",
nb_packets, pi, gfps, type, timestamp, pts, ndiff, diff, size);
srs_human_trace("Rtmp packet id=%"PRId64"/%.1f/%.1f, type=%#x, dts=%d, pts=%d, ndiff=%d, diff=%d, size=%d, (%s)",
nb_packets, pi, gfps, type, timestamp, pts, ndiff, diff, size, sbytes);
}

return ret;
Expand Down

0 comments on commit 4fe79a1

Please sign in to comment.