Skip to content
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

feat: convert mpd module to cmake #1234

Merged
merged 18 commits into from
Aug 5, 2023
Merged

Conversation

cosmin
Copy link
Contributor

@cosmin cosmin commented Jul 14, 2023

Issue #1047

packager/mpd/base/mpd_builder.cc Show resolved Hide resolved
packager/mpd/base/mpd_builder.cc Show resolved Hide resolved
@@ -32,6 +32,15 @@ class AdaptationSet;
class MediaInfo;
class Period;

class Clock {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created this class to replace the base::Clock and be able to override it for testing. Probably needs to be moved somewhere else from mpd_builder.h though, suggestions?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to create something similar already in Muxer in b1095f6. See packager/media/base/muxer.h.

We can always create a new folder to hold these things if we want to dedup them. I agree that this doesn't really belong in mpd.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved it to a separate file. This is used in the end to print ISO-8601 dates so I think it's better to keep this in std::tm instead of uint64_t timestamps. I updated the MuxerClock to use this Clock abstraction as well.

std::tm local_time = utc_time;
std::time_t utc_time_t = std::mktime(&local_time);
std::time_t offset = utc_time_t - std::mktime(std::gmtime(&utc_time_t));
mock_time_ = std::chrono::system_clock::from_time_t(utc_time_t + offset);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

had to jump through some hoops to be able to specify a std:tm in UTC for test injection. I think this works but perhaps there is a better way? The only better solutions I could find were C++20 though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In muxer, I have the clock abstraction return uint64_t in seconds since 1970 UTC. (Essentially the same as time_t.) Depending on how it is consumed, you could do the same here, and avoid time_point and std::chrono.

mpd_.InjectClockForTesting(std::unique_ptr<base::Clock>(
new TestClock(base::Time::FromUTCExploded(test_time))));
std::tm test_time{};
test_time.tm_year = 2016 - 1900; // Years since 1900
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like that this is the best option I could find to initialize a test time from something human readable. Worth adding some kind of helper method for this? Or is there some better solution?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tend to find ISO 8601 time strings to be pretty readable. If there's an easy way to parse those into the appropriate value type, I would use that. Ex: "2016-01-11T15:10:24Z"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, updated TestClock to use ISO-8601 format as the input

absl::big_endian::FromHost16(codec_data.channel_mask());
uint8_t byte1 = ec3_channel_map & 0xFF;
uint8_t byte2 = ec3_channel_map >> 8;
audio_channel_config_value = absl::StrFormat("%02X%02X", byte1, byte2);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couldn't find a better way to get the base::HexEncode here in big endian format, is this the best way to proceed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add another helper to packager/utils/hex_parser. I'm not certain you need to decompose it into individual bytes if you've already done a swap with absl. Just FromHost16 and StrFormat("%04X") should be fine, right? Or FromHost16 and BytesToHexString?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's where I started and that didn't work, the byte order was reversed, but looks like I was overthinking it. StrFormat("%04X", ...) works by itself, without FromHost16, going to big endian order is only important if we go byte at a time like the manual formatting.

audio_channel_config_value =
base::HexEncode(&ac4_channel_mask, sizeof(ac4_channel_mask) - 1);
absl::StrFormat("%02X%02X%02X", bytes[0], bytes[1], bytes[2]);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

likewise here for the uint32_t, perhaps I should the same approach for both AC3 and AC4 though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, I think. Swap and print/format/hexify without needing Span or individual bytes.

Also, it took me a while to see the "- 1" on the original. Please add a comment about us needing just 3 bytes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

packager/mpd/test/mpd_builder_test_helper.cc Outdated Show resolved Hide resolved
packager/mpd/test/xml_compare.cc Show resolved Hide resolved
packager/mpd/test/xml_compare.cc Show resolved Hide resolved
@cosmin cosmin force-pushed the cmake-mpd branch 2 times, most recently from ef81fe5 to 7a83ad5 Compare July 14, 2023 22:24
@cosmin
Copy link
Contributor Author

cosmin commented Jul 14, 2023

mpd\base\bandwidth_estimator.cc(109,12): warning C4244: 'return': conversion from 'double' to 'uint64_t', possible loss of data

bandwidth_estimator.cc is throwing an error on windows due to narrowing conversion from double to uint64. Since this one seems quite intentional, what is the right way to do this without tripping on C4244?

@cosmin cosmin requested a review from joeyparrish July 17, 2023 14:14
@cosmin cosmin force-pushed the cmake-mpd branch 2 times, most recently from 0418c29 to b1234b8 Compare July 21, 2023 10:43
@joeyparrish
Copy link
Member

bandwidth_estimator.cc is throwing an error on windows due to narrowing conversion from double to uint64. Since this one seems quite intentional, what is the right way to do this without tripping on C4244?

Is this the return 0.0; line? That's easy, just replace with return 0. There's no reason that should be a floating-point literal in a function returning uint64_t.

@cosmin cosmin force-pushed the cmake-mpd branch 4 times, most recently from 48de724 to 25e89b2 Compare July 31, 2023 00:44
std::vector<uint8_t> pssh;
base::HexStringToBytes(pssh_str, &pssh);

std::string pssh_hex_str = absl::HexStringToBytes(pssh_str);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd still like to clean this up.

packager/mpd/base/representation_unittest.cc Show resolved Hide resolved
packager/mpd/base/xml/xml_node_unittest.cc Show resolved Hide resolved
media_info_.set_segment_template_url("$Number$.m4s");
}

void TearDown() override { FLAGS_segment_template_constant_duration = false; }
void TearDown() override {
absl::SetFlag(&FLAGS_segment_template_constant_duration, false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This becomes unnecessary with FlagSaver.

packager/mpd/base/xml/xml_node_unittest.cc Show resolved Hide resolved
@@ -549,7 +550,7 @@ TEST_F(LiveSegmentTimelineTest, LastSegmentNumberSupplementalProperty) {
" <SegmentTemplate media=\"$Number$.m4s\" "
" startNumber=\"1\" duration=\"100\"/>"
"</Representation>"));
FLAGS_dash_add_last_segment_number_when_needed = false;
absl::SetFlag(&FLAGS_dash_add_last_segment_number_when_needed, false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This becomes unnecessary.

@cosmin cosmin requested a review from joeyparrish August 4, 2023 21:48
@cosmin cosmin merged commit 96acd1e into shaka-project:cmake Aug 5, 2023
@cosmin cosmin deleted the cmake-mpd branch August 5, 2023 03:45
@github-actions github-actions bot added the status: archived Archived and locked; will not be updated label Oct 4, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: archived Archived and locked; will not be updated
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants