Skip to content

Commit

Permalink
dash_mpd_add_video_adaptation_set/dash_mpd_add_audio_adaptation_set r…
Browse files Browse the repository at this point in the history
…ename
  • Loading branch information
ireader committed Jun 22, 2018
1 parent fa12c70 commit 2d38487
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 9 deletions.
4 changes: 2 additions & 2 deletions libdash/include/dash-mpd.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ void dash_mpd_destroy(dash_mpd_t* mpd);

/// @param[in] prefix dash adapation set name prefix
/// @return >=0-adapation id, <0-error
int dash_mpd_add_video_adapation_set(dash_mpd_t* mpd, const char* prefix, uint8_t object, int width, int height, const void* extra_data, size_t extra_data_size);
int dash_mpd_add_audio_adapation_set(dash_mpd_t* mpd, const char* prefix, uint8_t object, int channel_count, int bits_per_sample, int sample_rate, const void* extra_data, size_t extra_data_size);
int dash_mpd_add_video_adaptation_set(dash_mpd_t* mpd, const char* prefix, uint8_t object, int width, int height, const void* extra_data, size_t extra_data_size);
int dash_mpd_add_audio_adaptation_set(dash_mpd_t* mpd, const char* prefix, uint8_t object, int channel_count, int bits_per_sample, int sample_rate, const void* extra_data, size_t extra_data_size);

/// @param[in] adapation create by dash_mpd_add_video_adapation_set/dash_mpd_add_audio_adapation_set
int dash_mpd_input(dash_mpd_t* mpd, int adapation, const void* data, size_t bytes, int64_t pts, int64_t dts, int flags);
Expand Down
44 changes: 42 additions & 2 deletions libdash/src/dash-mpd.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
// https://en.wikipedia.org/wiki/ISO_8601
// Durations:
// 1. P[n]Y[n]M[n]DT[n]H[n]M[n]S
// 2. P[n]W
// 3. P<date>T<time>
// 4. PYYYYMMDDThhmmss
// 5. P[YYYY]-[MM]-[DD]T[hh]:[mm]:[ss]
// For example, "P3Y6M4DT12H30M5S" represents a duration of "three years, six months, four days, twelve hours, thirty minutes, and five seconds".
// "P23DT23H" and "P4Y" "P0.5Y" == "P0,5Y"
// "PT0S" or "P0D"
// "P0003-06-04T12:30:05"

#include "dash-mpd.h"
#include "dash-proto.h"
#include "mov-format.h"
Expand Down Expand Up @@ -91,6 +103,34 @@ struct dash_mpd_t
struct dash_adaptation_set_t tracks[N_TRACK];
};

/// @param[in] duration millisecond duration
/// @param[out] data ISO8601 duration: P[n]Y[n]M[n]DT[n]H[n]M[n]S
static int ISO8601Duration(int64_t duration, char* data, int size)
{
int n = 1;
data[0] = 'P';
if (duration > 24 * 3600 * 1000)
{
n += snprintf(data + n, size - n, "%dD", (int)(duration / (24 * 3600 * 1000)));
duration %= 24 * 3600 * 1000;
}

data[n++] = 'T';
if (duration > 3600 * 1000)
{
n += snprintf(data + n, size - n, "%dH", (int)(duration / (3600 * 1000)));
duration %= 3600 * 1000;

n += snprintf(data + n, size - n, "%dM", (int)(duration / (60 * 1000)));
duration %= 60 * 1000;
}

n += snprintf(data + n, size - n, "%dS", (int)((duration + 999) / 1000));
duration %= 1000;

return n;
}

static int mov_buffer_read(void* param, void* data, uint64_t bytes)
{
struct dash_adaptation_set_t* dash;
Expand Down Expand Up @@ -264,7 +304,7 @@ void dash_mpd_destroy(struct dash_mpd_t* mpd)
free(mpd);
}

int dash_mpd_add_video_adapation_set(struct dash_mpd_t* mpd, const char* prefix, uint8_t object, int width, int height, const void* extra_data, size_t extra_data_size)
int dash_mpd_add_video_adaptation_set(struct dash_mpd_t* mpd, const char* prefix, uint8_t object, int width, int height, const void* extra_data, size_t extra_data_size)
{
int r;
char name[N_NAME + 16];
Expand Down Expand Up @@ -312,7 +352,7 @@ int dash_mpd_add_video_adapation_set(struct dash_mpd_t* mpd, const char* prefix,
return 0 == r ? track->setid : r;
}

int dash_mpd_add_audio_adapation_set(struct dash_mpd_t* mpd, const char* prefix, uint8_t object, int channel_count, int bits_per_sample, int sample_rate, const void* extra_data, size_t extra_data_size)
int dash_mpd_add_audio_adaptation_set(struct dash_mpd_t* mpd, const char* prefix, uint8_t object, int channel_count, int bits_per_sample, int sample_rate, const void* extra_data, size_t extra_data_size)
{
int r;
char name[N_NAME + 16];
Expand Down
6 changes: 3 additions & 3 deletions libdash/test/dash-dynamic-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,19 @@ static int dash_live_onflv(void* param, int codec, const void* data, size_t byte
{
case FLV_VIDEO_AVCC:
if (-1 == dash->adapation_video && mpeg4_avc_decoder_configuration_record_load((const uint8_t*)data, bytes, &avc) > 0)
dash->adapation_video = dash_mpd_add_video_adapation_set(dash->mpd, dash->name.c_str(), MOV_OBJECT_H264, dash->width, dash->height, data, bytes);
dash->adapation_video = dash_mpd_add_video_adaptation_set(dash->mpd, dash->name.c_str(), MOV_OBJECT_H264, dash->width, dash->height, data, bytes);
break;

case FLV_VIDEO_HVCC:
if (-1 == dash->adapation_video && mpeg4_hevc_decoder_configuration_record_load((const uint8_t*)data, bytes, &hevc) > 0)
dash->adapation_video = dash_mpd_add_video_adapation_set(dash->mpd, dash->name.c_str(), MOV_OBJECT_HEVC, dash->width, dash->height, data, bytes);
dash->adapation_video = dash_mpd_add_video_adaptation_set(dash->mpd, dash->name.c_str(), MOV_OBJECT_HEVC, dash->width, dash->height, data, bytes);
break;

case FLV_AUDIO_ASC:
if (-1 == dash->adapation_audio && mpeg4_aac_audio_specific_config_load((const uint8_t*)data, bytes, &aac) > 0)
{
int rate = mpeg4_aac_audio_frequency_to((enum mpeg4_aac_frequency)aac.sampling_frequency_index);
dash->adapation_audio = dash_mpd_add_audio_adapation_set(dash->mpd, dash->name.c_str(), MOV_OBJECT_AAC, aac.channel_configuration, 32, rate, data, bytes);
dash->adapation_audio = dash_mpd_add_audio_adaptation_set(dash->mpd, dash->name.c_str(), MOV_OBJECT_AAC, aac.channel_configuration, 32, rate, data, bytes);
}
break;

Expand Down
4 changes: 2 additions & 2 deletions libdash/test/dash-static-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ static int s_adapation_audio;
static void mp4_onvideo(void* mpd, uint32_t track, uint8_t object, int width, int height, const void* extra, size_t bytes)
{
s_track_video = track;
s_adapation_video = dash_mpd_add_video_adapation_set((dash_mpd_t*)mpd, "dash-static-video", object, width, height, extra, bytes);
s_adapation_video = dash_mpd_add_video_adaptation_set((dash_mpd_t*)mpd, "dash-static-video", object, width, height, extra, bytes);
}

static void mp4_onaudio(void* mpd, uint32_t track, uint8_t object, int channel_count, int bit_per_sample, int sample_rate, const void* extra, size_t bytes)
{
s_track_audio = track;
s_adapation_audio = dash_mpd_add_audio_adapation_set((dash_mpd_t*)mpd, "dash-static-audio", object, channel_count, bit_per_sample, sample_rate, extra, bytes);
s_adapation_audio = dash_mpd_add_audio_adaptation_set((dash_mpd_t*)mpd, "dash-static-audio", object, channel_count, bit_per_sample, sample_rate, extra, bytes);
}

static void mp4_onread(void* mpd, uint32_t track, const void* buffer, size_t bytes, int64_t pts, int64_t dts)
Expand Down

0 comments on commit 2d38487

Please sign in to comment.