New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding support for generation of the EXT_X_PROGRAM_DATE_TIME tag for … #814
Conversation
…HLS playlists, with fixed UTC timezone
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
1 similar comment
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
@googlebot I signed it! |
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
1 similar comment
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
CONTRIBUTORS
Outdated
@@ -45,3 +45,4 @@ Sergio Ammirata <sergio@ammirata.net> | |||
Thomas Inskip <tinskip@google.com> | |||
Tim Lansen <tim.lansen@gmail.com> | |||
Weiguo Shao <weiguo.shao@dolby.com> | |||
Artem Bogdanov <ykidia@gmail.com> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you move it after line 27, i.e. in alphabetical order?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ping
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
packager/hls/base/media_playlist.cc
Outdated
@@ -345,6 +368,8 @@ MediaPlaylist::MediaPlaylist(const HlsParams& hls_params, | |||
name_(name), | |||
group_id_(group_id), | |||
media_sequence_number_(hls_params_.media_sequence_number) { | |||
start_timestamp = base::Time::Now().ToDoubleT(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be generated in the master playlist and passed to the media playlist otherwise there will be inconsistencies among the the media playlists.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Master playlist doesn't create any media playlists, only manipulates them in list(s) and, finally, writes all to file.
Wherein media playlist can be used without master playlist and, therefore, must generate the timestamp inside itself.
Thus, if we want to generate timestamps in master playlist, then we should provide some offset for every media playlist and for all their segments, when master playlist writing to a file. It looks like a dirty hack for me.
Simple hls notifier, on the contrary, creates media playlists and master playlist and thus, I think, can be used for the timestamp generation.
is it correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that is correct. Let me clarify what I mean.
Per HLS specification:
o If any Media Playlist in a Master Playlist contains an EXT-X-
PROGRAM-DATE-TIME tag, then all Media Playlists in that Master
Playlist MUST contain EXT-X-PROGRAM-DATE-TIME tags with consistent
mappings of date and time to media timestamps.
The date and time must be consistent for all media playlists in the master playlist.
However, in your implementation, the |start_timestamp| is re-calculated for every media playlist. They will not be consistent, as different media playlists are created at different time. Although the difference may be small in most cases, likely negligible in some cases, but it will be significant sometimes.
To ensure a consistent date time mapping, there should only be one source of date time mapping. The best approach is to have a single mapping of media timestamp to absolute date/time, which is then propagate to all media playlists. One way to achieve that is to use master playlist to coordinate the mapping. Of course, there are other ways to do it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, specification says that "the date and time must be consistent for all media playlists in the master playlist". And the current solution does not contradict this. Specification does not say that "the date and time must be consistent ACROSS all media playlists in the master playlist". But even so: for example, one stream came (started) immediately, another after 678 ms, the third after 5 s, the fourth after 1.5 s, etc; how to make their timestamps consistent with each other if the streams doesn't reference each other in any way? Do you want to make their start timestamps are the same? Then content will be corrupted, and that's not correct. But if not (let's leave individual start timestamps) - every media playlist initializes its start timestamps upon creating, this happens immediately when the corresponding stream starts.
On the other hand, we're getting current system date and time to initialize start timestamps. This is a really single source of date and time mapping.
Please explain if I misunderstood.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that the main problem is that you disagree that the date/time to media timestamp mapping has to be consistent across ALL media playlists.
If any Media Playlist in a Master Playlist contains an EXT-X-
PROGRAM-DATE-TIME tag, then all Media Playlists in that Master
Playlist MUST contain EXT-X-PROGRAM-DATE-TIME tags with consistent
mappings of date and time to media timestamps.
It mentions clearly that "all media playlists must ... with consistent mappings of date and time to media timestamps".
Do you still have a different interpretation of the statement?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
You said "across ALL". But specification NOT.
I asked you "please explain if I misunderstood" - I meant "describe how you imagine the result", but not to simply repeat your previous post.
And did you really read my explanations? Where the mistake?
Anyway, how should what you want look like? Should all streams (media playlists) have the same start timestamps regardless of the arrival time? I'm really trying to understand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ping
packager/hls/base/media_playlist.cc
Outdated
AddSegmentInfoEntry(file_name, start_time, duration, start_byte_offset, size, | ||
start_timestamp); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we insert it for first segment and for the segments after ext-x-discontinuity only?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We CAN insert it everywhere only once or more but if we did it then we MUST insert it after all ext-x-discontinuity. So, we CAN simply insert it for all segments, as far as I understand RFC 8216.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. I think it will be simpler if we just consider it for every ext-x-discontinuity. I am fine with your approach too but you'll need to take care of the i-frame playlist too. See the comment above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
packager/hls/base/media_playlist.cc
Outdated
@@ -423,13 +448,15 @@ void MediaPlaylist::AddSegment(const std::string& file_name, | |||
: std::next(iter)->timestamp; | |||
AddSegmentInfoEntry(file_name, iter->timestamp, | |||
next_timestamp - iter->timestamp, | |||
iter->start_byte_offset, iter->size); | |||
iter->start_byte_offset, iter->size, start_timestamp); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
start_timestamp should be incremented by "next_timestamp - iter->timestamp".
Also see the comment below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
packager/hls/base/media_playlist.h
Outdated
@@ -268,6 +273,8 @@ class MediaPlaylist { | |||
bool target_duration_set_ = false; | |||
uint32_t target_duration_ = 0; | |||
|
|||
double start_timestamp = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ends with "_" to be consistent. Can you also add a comment explaining what it is?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ping.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
packager/hls/base/media_playlist.cc
Outdated
DEFINE_bool(hls_ext_x_program_date_time, | ||
false, | ||
"hls print EXT-X-PROGRAM-DATE-TIME tag"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you define it in https://github.com/google/shaka-packager/blob/master/packager/app/hls_flags.cc instead?
And then add a bool in HlsParams?
https://github.com/google/shaka-packager/blob/master/packager/hls/public/hls_params.h
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ping
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -299,6 +356,41 @@ TEST_F(MediaPlaylistMultiSegmentTest, SetTargetDuration) { | |||
ASSERT_FILE_STREQ(kMemoryFilePath, kExpectedOutput); | |||
} | |||
|
|||
TEST_F(MediaPlaylistMultiSegmentTest, WriteToFileWithTagExtXProgramDateTime) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can remove these new tests except the first one as they don't add more test coverage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest also not to remove the last test because it adds case when the time stamp changes across key frames before adding segment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
packager/hls/base/media_playlist.cc
Outdated
DEFINE_bool(hls_ext_x_program_date_time, | ||
false, | ||
"hls print EXT-X-PROGRAM-DATE-TIME tag"); | ||
#include "packager/app/hls_flags.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move it before line 21, i.e. put it in alphabetical order
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
packager/hls/base/media_playlist.cc
Outdated
uint64_t previous_segment_end_offset); | ||
uint64_t previous_segment_end_offset, | ||
bool use_program_date_time, | ||
double start_timestamp); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you rename |start_timestamp| to |program_date_time| to avoid confusion as we already have a start_time in this class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
packager/hls/base/media_playlist.cc
Outdated
@@ -345,6 +368,8 @@ MediaPlaylist::MediaPlaylist(const HlsParams& hls_params, | |||
name_(name), | |||
group_id_(group_id), | |||
media_sequence_number_(hls_params_.media_sequence_number) { | |||
start_timestamp = base::Time::Now().ToDoubleT(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that the main problem is that you disagree that the date/time to media timestamp mapping has to be consistent across ALL media playlists.
If any Media Playlist in a Master Playlist contains an EXT-X-
PROGRAM-DATE-TIME tag, then all Media Playlists in that Master
Playlist MUST contain EXT-X-PROGRAM-DATE-TIME tags with consistent
mappings of date and time to media timestamps.
It mentions clearly that "all media playlists must ... with consistent mappings of date and time to media timestamps".
Do you still have a different interpretation of the statement?
@kqyang, please, let's continue with this PR. Tell me what is stopping it? Are there some political reasons? If the problem is only in our different interpretation of the specification, then I can offer two options:
|
@Ykidia I want to make sure that we are doing the right thing. Per my understanding, what you did in this PR violates HLS specification. I could be wrong, but I don't see your argument and reply on #814 (comment). If you have a different interpretation of this clause, I want to understand how you interpret it.
Let us have a consensus on the spec before moving forward. We can worry about how that can be implemented later. |
Take a look at a real example of related master and media playlists: master.m3u8
stream_0.m3u8
stream_1.m3u8
stream_2.m3u8
stream_3.m3u8
<...> stream_7.m3u8
Notice how all media playlists have different timestamps, albeit slightly. |
@Ykidia Thanks for the data. I understand that it works well in most cases. Unfortunately, it will break if we put it in large scale use as it already shows inconsistencies. For example, if one of the stream is delayed by 0.5 seconds, which is possible in live case, players will see a difference of 0.5 seconds between two renditions although the two are supposed to be presented at the same time.
I am confused with your statement. Apparently the timestamp does not match between different representations, which clearly violates HLS spec. Again, please explain your interpretation if you have a different understanding of how If you are concerned with how we can achieve consistent mapping, we can discuss that later once we agree on what it means. It is do-able and will just be slightly more complicated that what you have now. |
"Supposed to be"? This is just a guess based on the special-case data, where all segments are the same length; but they do not have to be the same, neither between media playlists, nor even within the single media playlist. And what will be supposed to be then? If all segments are different length, how to detect reference time stamp unambiguously? The fact of the matter is that HLS spec. does NOT say, that timestamps must
, NOR contain any similar words to "between" or "across".
This clearly means only that if we want to insert EXT-X-PROGRAM-DATE-TIME tags to one of the media playlist in master playlist, then we MUST to insert the tag to all the others media playlists in that master playlist. Moreover, simple tag insertion is not enough - timestamps in every media playlist must be consistent.
Hmm, however, you intrigued me. Perhaps I do not fully understand your point of view? Please tell me in more detail how it should look. As I said earlier, I am trying to understand as much as possible.
|
Hi @Ykidia, I tend to have the same interpretation of the HLS RFC as @kqyang and understand that the I've reworked your proposal in the following patch: https://github.com/Ykidia/shaka-packager/commit/27cf91ccf05ebca7c753208c1e02941f39de319e Basically, instead of computing a "reference" time in each playlists independently I moved this logic to the upper layer in simple_hls_notifier.cc I also changed the option to be able to specify an offset between current time and stream generation time, this way someone knowing that he's receiving the stream with a fixed delay can compensate for this delay. And finally I only kept one I've also submitted a pull request with stashed commits: #840 |
@kqyang, I spoke to a real expert on this subject. His experience is greater, and his qualifications are higher than those with whom I worked and whose opinion I fiercely defended here. He explained to me that the solution to the issue is more difficult than I thought. I apologize for my harsh tone in this conversation. I was wrong and you are right. Thank you for your patience! |
…HLS playlists, with fixed UTC timezone.
Command-line switch to go on with this tag: --hls_ext_x_program_date_time.
Probably closes issue [#365 ].