Commit Graph

1113 Commits

Author SHA1 Message Date
Jacob Trimble 9a34b9c3f3 Fix trick-mode property values.
Change-Id: Idc59c0002cd999e8a39862615949a339a2fe0780
2020-11-10 14:01:23 -08:00
KongQun Yang 741ae7f545 Fix docker build
Alpine does not support python3 yet, but depot_tools enabled python3
by default recently.

Disable python3 for now.

Fixes #763.

Change-Id: I57cd414702e89cafbe1b8beee810f89760129d10
2020-11-09 18:13:51 +00:00
Jacob Trimble 8e85862bda Ignore unsupported H26x streams.
This adds a new path when parsing MPEG2-TS streams to ignore unsupported
streams.  This allows extracting supported streams when some of the
streams are unsupported.  For example, you can extract audio from a
file that has unsupported video.

Change-Id: I608fcb19d0a573bfd35e9272f60b0b69346ae11a
2020-11-09 18:11:07 +00:00
Jacob Trimble 10e71680a1 Parse WebVTT regions and styles.
This adds more generic settings for regions and CSS styles.  These are
global settings, so they go on the StreamInfo object.

Change-Id: Ibb76c060206152ccf8e9a067c09877226f67c927
2020-11-09 18:08:42 +00:00
KongQun Yang 4a777b6207 [HLS] Fixes attributes for DVS tracks
Always set AUTOSELECT=YES for DVS tracks and also exclude it from
standard AUTOSELECT and DEFAULT configuration logic.

Fixes #857.

Change-Id: Ie179d02390ff09f6e8c0b54892c1d6d32a3c38d6
2020-11-05 02:56:53 +00:00
Jacob Trimble 1f21cc78cd Add style support for cue fragments.
Now text cues are composed of nested fragments that can be individually
styled.  This allows portions of the cue to be bold, etc.  The
WebVTT parser doesn't parse the inputs, but the original tags are
preserved in WebVTT output.  The WebVTT output will add tags if the
style elements are present in the cue object.

Change-Id: I6abba4175e376e4f753193f7d8cac63e958d3c89
2020-10-21 10:53:59 -07:00
Jacob Trimble f4c07b9ce0 Work around non-deterministic tests.
We currently have a bug about non-deterministic output in the MPD
generator.  This works around that bug by optionally doing everything
in a single thread.  This allows us to run manifest comparisons without
making the major changes needed to add that feature.

Issue #177

Change-Id: I10e1084dac77841220161fbd2575cdcb5c13c00e
2020-10-20 22:00:39 +00:00
Jacob Trimble 414f4589c8 Parse TextSettings from WebVTT.
Now the Cue settings are a generic object that is parsed in WebVTT.
This will allow setting the settings in different parsers without having
to use WebVTT-specifics.

Change-Id: I36689bec725bd2e515af962b7174fc5977f96fa2
2020-10-20 21:50:06 +00:00
Jacob Trimble c169c83613 Add integration test for WebVTT in MP4.
Change-Id: Ic8cd785d1fefde4004f27cfce346df2b2a8f643e
2020-10-19 10:55:35 -07:00
Jacob Trimble b2220eb0c6 Add text fragment and setting types.
This sets the groundwork for more generic text cues by having a more
generic object for the settings and the body.  This also changes the
TextSample to be immutable and accepts the fields in the constructor
instead of using setters.

Change-Id: I76b09ce8e8471a49e6bf447e8c187f867728a4bf
2020-10-19 10:39:17 -07:00
Jacob Trimble 56908a83a7 Convert text WebVTT output to muxer.
Now text-based WebVTT also uses the generic media pipeline.  This
converts the WebVttTextOutputHandler to a WebVttMuxer to be more
consistent with the other muxer types.

This also allows choosing between single-segment text and multi-segment.
Before, we would generate both and use single-segment for DASH and
multi-segment for HLS; but now you can choose between either and either
are supported in both DASH and HLS.

Change-Id: I6f7edda09e01b5f40e819290d3fe6e88677018d9
2020-10-19 17:24:38 +00:00
Jacob Trimble 2909ca0c77 Handle segmented text same as audio/video.
Now the same pipeline for handling the audio/videos streams will handle
the segmented text streams too.  This doesn't apply to the text output,
only to the MP4 variants.  This also fixes a bug where we added the
X-TIMESTAMP-MAP tag even when there wasn't TS streams; this doesn't
otherwise change the behavior around that tag.

Change-Id: I03f7cea56efa42e96311c00841330629a14aa053
2020-10-07 17:49:03 +00:00
Jacob Trimble 9babfb883b Fix segmented WebVTT test.
The test added in the previous CL was broken due to a rebase on another
change.  This subtly changed some of the byte offsets that broke the
test.  This wasn't caught since I didn't rebase and re-run the tests
before merging.

Change-Id: Id7e4c7688278eae37da1a14f1648263b4dda98cd
2020-09-16 13:24:16 -07:00
Jacob Trimble e3bc85f12d Make WebVttParser a MediaParser.
This changes it from an OriginHandler to a MediaParser and moves the
handling of it to the Demuxer.  This will allow more generic handling
of text by giving it the same abstractions as video/audio handling.

Change-Id: Ibbde3c84d228ec8e83af1ed266ea97dbc9589c24
2020-09-16 20:12:48 +00:00
Jacob Trimble ba33a63693 Add TextSample to MediaParser.
In addition to the MediaSample handling of the MediaParser, this now
adds callbacks for TextSample.  This allows reading text streams from
the media files.

Change-Id: I6c00e286e98bc9aafe05b99cf2f7ce6f89d167a9
2020-09-16 20:09:28 +00:00
Jacob Trimble 748e7e0056 Make the text readers use streams.
Instead of having the text readers reading from the file directly, they
now accept the data as a stream.

Change-Id: Id1b32c867a8058a68ae7aab5c568f77672a4401d
2020-09-16 20:06:51 +00:00
koln67 5b9fd409a5
[MP4] Change major brand from isom to mp41
This fixes warnings that 'isom' can only be a compatible instead of major brand.

Issue #755.
2020-09-08 15:45:21 -07:00
koln67 562040e000
[TS] Calculate frame rate using the second sample
Related to #751.
2020-09-02 14:27:02 -07:00
Jacob Trimble 4c0d38bde3 Don't use Chromium sysroot.
The Chromium sysroot has a broken C++11 implementation that doesn't
allow us to use <condition_variable> or <chrono>.  So we need to use the
system sysroot to use all C++11 features.

Change-Id: I41bec7ebddf598e1bf0494ee8bb2844e67bc8acf
2020-09-01 17:59:52 +00:00
koln67 54bf394c03
[HLS] Ensure playlists with TS streams include FRAME-RATE
It fixes the FRAME-RATE missing issue in #816.
2020-08-21 12:04:24 -07:00
koln67 28074e5c96
[HLS] Add support for independent segments tag
Fixes #564.
2020-08-19 11:17:21 -07:00
akata01 6298f49d9e
Don't fail if input contents contain SampleGroupDescriptionBox with 0 entries
Fixes #812.
2020-08-09 18:44:16 -07:00
koln67 5c91e54b8b
[HLS] Don't include FRAME-RATE in EXT-X-STREAM-INF
Part of #816.
2020-08-06 21:51:35 -07:00
koln67 caa47e374d
Properly handle AVC profiles with SPS extension
Part of #755 to improve DASH spec compliance.
2020-08-05 17:08:53 -07:00
sr90 11d69896c0
Write to memory file before writing to file for WebM segments generation (#803)
The change is needed to address #554.
2020-07-27 21:32:56 -07:00
koln67 a8ea7fd085
Always set ES_ID to 0 when writing ES Descriptor in mp4 (#798)
Required by ISO/IEC 14496-14:2018 and ISO/IEC 23000-19:2018.

Issue #755.
2020-07-15 14:14:15 -07:00
sr90 db5413ed7a
Write to buffer before writing to file for TS segments generation. (#790)
The refactoring is needed to address #554.
2020-07-04 15:18:30 -07:00
Weiguo Shao 540c0aaffb
Added AC-4 codec support (#795)
Closes #754.
2020-07-04 14:55:28 -07:00
Joe Foraci 6b036b9bb1
Support different IVs for each track (#793)
This is supported by allowing IV to be specified in the "key_info_string".

Fixes #543.
2020-06-25 20:37:50 -07:00
Jacob Trimble 1911c1beaa Add flag for extra PlayReady header data.
Fixes #756

Change-Id: I4fa6328480130675a0257fd2c6663d91729cf72c
2020-06-22 22:55:25 +00:00
Jacob Trimble 665e784cbd Move PSSH generation to EncryptionHandler.
The KeySource now only handles fetching the keys and loading any PSSH
info from the license; it will not handle generating new PSSH info
based on the config.

This will allow the PSSH generation to access to the full
EncryptionConfig so we can add additional options to it.

Issue #756

Change-Id: Ia67387aa3d5ec0d723b7f5f21fc517f64c840393
2020-06-22 22:51:44 +00:00
Jacob Trimble 51fe84f9d5 Provide better diffs for MP4 failures.
If the user has the GPAC MP4 tools installed, this will use that to
provide a better, text-based diff of the MP4 files.  This makes looking
at test failures much better than just "binary files differ".

Change-Id: Ifdca54c02226a9f0fe9ddcf9c6b28e960e568111
2020-06-10 17:12:24 +00:00
Zajcev Evgeny 8913dbda85
Mpeg1 Audio: Support for iso-bmff output (#780)
Issue #779.
2020-06-06 17:18:00 -07:00
Jacob Trimble f0107beb9e Make some of the test args better.
Change-Id: I473f3318c6913e78f60a19166a54f7c873078b73
2020-06-04 15:05:40 -07:00
Jacob Trimble 719668aa1c Fix output in Python3 when tests fail.
Change-Id: Icd7552cee1336c10fe42f9f0bae175171347d369
2020-06-04 14:59:40 -07:00
Jacob Trimble 7e41937bb1 Consolidate key system enums.
There were several enum types that all were used for key systems.  This
combines them into one to make it more clear and only needing to update
one.  This also uses a bit field to specify multiple key systems instead
of using a std::vector.

Change-Id: Ia88039835492a5bd47f449ba4b76187046deeec0
2020-06-04 17:19:18 +00:00
Weiguo Shao 4f068bfaa8
Support DD+JOC in DASH and HLS (#775)
Spec: ETSI TS 102 366 V1.4.1
HLS: https://developer.apple.com/documentation/http_live_streaming/hls_authoring_specification_for_apple_devices/hls_authoring_specification_for_apple_devices_appendices
DASH: https://github.com/Dash-Industry-Forum/DASH-IF-IOP/issues/268

Closes #753.
2020-06-03 22:02:49 -07:00
KongQun Yang f51e98c422 Fix possible incorrect resolutions with avc3
The resolution values are uninitialized when parsing AVC decoder
configuration record if it does not contain parameter sets (SPS/PPS),
thus they could contain undefined values.

Fixes #750.

Change-Id: I6d54ec9f8740acd45a67b4b7d69031e097fbacc1
2020-06-03 22:59:30 +00:00
KongQun Yang 1b262b5784 Fix failures with latest gpylint
Change-Id: Id80000b530b0582b907730db9311075a7f5307fa
2020-06-03 22:59:22 +00:00
Zajcev Evgeny 98a9d1baf6
Support for MPEG-1 Audio in mpeg2ts I/O and packed-audio output (#778)
Implemented according to https://www.datavoyage.com/mpgscript/mpeghdr.htm.

Closes #779.
2020-06-02 17:32:19 -07:00
Alen Vrečko 15934d66c0
H265: Fixed inaccurate parsing of ref pic list modification (#773)
Fixes #717: playback issue of HEVC content with cbcs encryption in AVplayer.
2020-05-24 11:51:42 -07:00
yokoyama10 ca47cd7a0d
Fixed build error with Python 3 (#765)
Add parentheses to print methods in `generate_license_notice.py`.
2020-05-06 11:21:23 -07:00
sr90 7aefbeb27f
Adding check for creating captions with dash_only and hls_only. (#761)
Fix the problems in the previous CL for #651.
2020-04-29 17:39:12 -07:00
Sergio Garcia Murillo dba798798b
Prevent seg fault when finalizing empty segment (#759)
Fixes #757.
2020-04-25 14:09:48 -07:00
Tim Lansen 8e113af215
[DASH] Include <mspr:pro> alongside to <cenc:pssh> for PlayReady (#749)
Configurable under flag --include_mspr_pro_for_playready. True by default.

Closes #743.
2020-04-17 10:20:03 -07:00
sr90 fbcc8f31e3
Consider DASH stream descriptor field "roles" for WebVTT text streams. (#740)
Fixes #708.
2020-03-26 23:16:07 -07:00
sr90 4bfa603b52
[DASH] Support TrickPlay using separate trick play specific streams (#736)
Closes #732.
2020-03-24 12:15:30 -07:00
Joey Parrish 962baf0286 Fix reading WebVTT from a pipe
Opening a named pipe can block until both ends are open, and we cannot
control when the other end will be open.  Ideally, we would always
open files in a thread so that Packager can be used with piped inputs
from naive applications without a potential deadlock.

This change will defer opening WebVTT files until the parser Run()
method is called from a thread.  This way, WebVTT files being sent in
from a pipe will never be able to block the main thread.

Previously, files were opened on the main thread before calling the
parser constructor, passing the open file to the constructor as an
argument.  I also tried doing it in the parser's InitializeInternal()
method, but that is also called from the main thread.

Change-Id: I54cc68ed9d48a8dc697829119be84d4065b1ae1c
2020-03-19 20:25:07 -07:00
Joey Parrish 9a3ea747a4 Fix python style errors
Change-Id: I78d387329cf4d9b4bead30e4df5d684b31ef104e
2020-03-19 15:50:25 -07:00
sr90 55349aa4c8
Adding --allow_codec_switching (#726)
To allow adaptive switching between different codecs.

Closes #542.
2020-03-17 19:33:44 -07:00
Abhay Sundaram 28537034e8
Fix git not found error on Windows when running gclient (#728)
It happens if `git` is not installed as a standard alone application, but as a shell command.

Fixes #724.
2020-03-13 09:22:12 -07:00
Tomohiro IKEDA c576814d30
Clean up descriptions in mpd command line flags (#730)
Remove the 'Exclusive' statements on --mpd_output and --output_media_info as they
can already work together.
2020-03-11 10:25:33 -07:00
sr90 a1dd82d478
Support dash_only and hls_only parameters (#721)
This allows conditional stream descriptors which apply to DASH or HLS only.

Closes #651.
2020-03-06 10:19:47 -08:00
KongQun Yang 055c67888b Add an option to allow write |mvex| before |trak|
Under command line flag --mvex_before_trak.

This is needed to workaround Android MediaExtractor bug which
requires |mvex| to appear before |trak|.

Closes #711.

Change-Id: Id41d71af5c0016f59023dda6408bbf502e12ac55
2020-02-28 02:10:08 +00:00
KongQun Yang 4028bf727b Allow specifying protection pattern for pattern encryption
Added --crypt_byte_block, --skip_byte_block to allow users to specify
protection pattern other than 1:9 for pattern based encryption scheme,
e.g. cbcs and cens.

Closes #710.
b/147307451

Change-Id: I9f64a7639170c737f138572689b28d17286325c7
2020-02-28 00:50:58 +00:00
sr90 1ca873f453
[DASH] Support signalling of last segment number (#713)
Per https://dashif.org/docs/DASH-IF-IOP-v4.3.pdf 4.4.3.6 Signalling the last segment number in Period, there are three ways to signal the last segment number:

  a. Use the lmsg signalling as defined in clause 4.4.3.5.
  b. Use the Segment Timeline with @r value greater or equal to 0.
  c. Add a Supplemental Descriptor with @schemeIdUri set to http://dashif.org/guidelines/last-segment-number with the @value set to the last segment number.

We do not support (a). This change adds support for (c) when Segment Timeline (b) is not used, i.e. when Representation has constant duration (could be approximate).

Under flag --dash_add_last_segment_number_when_needed (disabled by default).
2020-02-24 23:12:53 -08:00
KongQun Yang ce932f68a2 Change AV1 cbcs to protect all bytes of decode_tile structure
AV1-ISOBMFF spec is updated recently to use start alignment instead of
end alignment for cbcs:

for the protected scheme cbcs:
- BytesOfProtectedData SHALL start on the first byte and end on the
  last byte of the decode_tile structure (including any trailing bits).
- A subsample SHALL be created for each tile, even if its size is less
  than 16 bytes.
- ...

cenc protection scheme is not affected.

Closes #698.

Change-Id: Ic83a478fb2602d830c30daf3206a1c2d2c238a08
2020-02-11 22:15:11 +00:00
KongQun Yang 624b2ca725 Fix possible compilation errors with gcc
Remove custom constructors, which is no longer needed with C++11. Use
C++ struct zero initialization instead.

Fixes #686.

Change-Id: I512da9f23a250e8b9ebf8bb8e0a39ad0f822d0d3
2020-02-11 05:46:27 +00:00
KongQun Yang b900565a0f Support Dolby Vision backward compatible profiles
Added Dolby Vision backward compatible signalling, i.e. for Dolby Vision
profile 8, both base codec without Dolby Vision and HDR codec with Dolby
Vision are signalled.

This is achieved by using a new MuxerListener implementation
MultiCodecMuxerListener, which wraps multiple child MuxerListeners and
is able to delegate to the child MuxerListeners based on the codecs in
the stream.

Closes #341.

Change-Id: I1967bb1ed503087cdd011c364e5fb5647d516ca4
2020-02-11 05:24:09 +00:00
Daniel Cantarín 1ed7de268d
Fix timestamp truncated to 32 bits in TS segment with $Time$ in template
Fixes #701.
2020-02-01 18:37:26 -08:00
Daniel Cantarín 7aab7a8b50
Add --hls_media_sequence_number to support custom value in HLS
HLS uses the EXT-X-MEDIA-SEQUENCE tag at the start of a live playlist in
order to specify the first segment sequence number. This is because any
live playlist have a limited number of segments, and they also keep
updating with new segments while removing old ones. When a player refreshes
the playlist, this information is important for keeping track of segments
positions.

When the packager starts, it naturally starts this count from zero. However,
there are many situations where the packager may be restarted, without this
meaning starting this value from zero (but continuing a previous sequence).
The most common situations are problems in the encoder feeding the packager.

With those cases in mind, this parameter allows to set the initial
EXT-X-MEDIA-SEQUENCE value. This way, it's possible to continue the sequence
number from previous packager run.

Closes #691.
2020-01-31 10:25:19 -08:00
KongQun Yang ff5f3f3abc Call WSAStartup once for every new socket
Some users are seeing problems with only one WSAStartup call.

WSAStartup can be called more than once:
https://docs.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-wsastartup

Fixes #643.

Change-Id: I81e0e7979d6a586da452984a96a8557b7b3ce7f6
2019-11-20 14:00:51 -08:00
Tomohiro IKEDA 0b53b40428 Change --generate_static_mpd to --generate_static_live_mpd (#672) 2019-11-15 11:53:47 -08:00
Vladimir Kazakov 981515e6c8 Generate correct PlayReady PSSH data when AES-CBC encryption is used
Fixes #602.
2019-11-15 11:48:48 -08:00
KongQun Yang 1bcaf0a835 Add an end to end test for non square pixels
Issue #663.

Change-Id: Iaba52f0fc6c97d413e973f9a3d8c74cf8c83aa03
2019-10-23 18:41:18 +00:00
KongQun Yang cb8b27e491 Properly initialize crypto engine to enable HWAES
Call CRYPTO_library_init to properly initialize crypto engine, which
enables AES-NI (Hardware AES) if it is supported by CPU.

Also added a performance benchmark test.

Closes #198.

Change-Id: I962a2da588d2f4f6cbe00c83ecc9a832db0e6042
2019-10-22 21:37:12 -07:00
KongQun Yang c80f053ba2 Roll boringssl/src fc9c67599..76918d016
Also roll_boringssl.py script is also adjusted to work with latest
boringssl.

Disable ASM compilation on Windows x64 which fails to compile. It also
means there are no HW AES on Windows x64.

Issue #198.

Change-Id: Ib7e8ff506f014c8c733f1882eeeddbe34fa28511
2019-10-23 04:32:33 +00:00
KongQun Yang 0342adb132 Fix possible packager hangs when reading mp4 from FIFO
For MP4 files, mp4 parser tries to open and read the same file again
to handle trailing MOOV box.

Open FIFO again may result in packager hang.

Update the code to only attempt to load MOOV for local regular files,
as FIFO and remote files are unseekable anyway.

Fixes #664.

Change-Id: Ib286d2876d202cd5a248ffe70b13589b3cc74bc9
2019-10-21 18:49:52 -07:00
KongQun Yang 7973c5396f Replace Dolby Vision test content
Issue #341

Change-Id: I530b0768341e352f6ee0a1326540cd5712f01638
2019-10-09 21:34:53 +00:00
KongQun Yang 4f14a6f973 [HLS] Always set FRAME-RATE attribute
Although FRAME-RATE is optional per HLS specification, but per HLS
Authoring Specification for Apple Devices (https://apple.co/30n90DC):
  Each EXT-X-STREAM-INF tag MUST have a FRAME-RATE attribute.

Also, iOS and TVos refuse to play the content if VIDEO-RANGE is
present but FRAME-RATE is missing.

Issue #632, #634.

Change-Id: Ica282f023a7e8538f7b506094e2286840cf5c193
2019-10-09 21:20:32 +00:00
KongQun Yang b70da0ed93 Add --quiet to suppress LOG(INFO) outputs
Closes #661.

Change-Id: Ic75479fba4f8dc26146b42b85ab95af6151302b6
2019-10-08 10:20:51 -07:00
KongQun Yang ab8fa87d18 [HLS] Always signal Dolby Vision as PQ
Issue #341.

Change-Id: I9665ba032b1e069500d866281cb8569ce59876f9
2019-10-04 16:19:07 -07:00
KongQun Yang 0f15ce149b [HLS] Support FRAME-RATE attribute
Calculate FRAME-RATE from sample duration as in the DASH solution.

Right now calculated frame-rate may not be accurate in some scenarios,
so we avoid setting the attribute in HLS unless it is more than 30
fps. We will set it unconditionally once it is fixed.

Fixes #634.

Change-Id: I87b6e9a047d959ae88dd4dcb2b4786527ba5c9fc
2019-10-04 22:50:34 +00:00
KongQun Yang 3f909fa551 [HLS] Support HDR signaling, i.e. VIDEO-RANGE attribute
- Parse and extract transfer_characteristics from H264/H265 VUI
  parameters.
- Set VIDEO-RANGE attribute in HLS according to HLS specification:
  https://tools.ietf.org/html/draft-pantos-hls-rfc8216bis-02#section-4.4.4.2
- Also added an end to end test.

Fixes #632.

Change-Id: Iadf557d967b42ade321fb0b152e8e7b64fe9ff3e
2019-10-04 22:50:20 +00:00
KongQun Yang 8029004c6b Add HEVC Dolby Vision support
- Add relevant FOURCCs for Dolby Vision.
- Parse DOVIDecoderConfigurationRecord (dvcC, dvvC) to generate
  Dolby Vision codec string.
- Propagate Dolby Vision configs (dvcC, dvvC, hvcE) from Demuxer
  to Muxer.
- Add a Dolby Vision end to end test.

Support for backward compatibility signaling in DASH and HLS will be
added in a later CL.

Issue #341

Change-Id: If1385df5f48e04b59cb7661130bea48e26b453bf
2019-10-03 23:04:15 +00:00
Phillip Baxter 00fde07bf7 Fix non standard channel layout AAC audio with PCE encoding
Latest version of FFmpeg encodes non standard channel layout, e.g. 5.1(side), in AAC using PCE.

This is now supported with the below changes:
- Allow channel_configuration in ADTS header to be 0, as the cctual channel layout is specified 
  in PCE.
- Add GetFrameSizeWithoutParsing to determine the frame size before actually parsing the frame.
- Skip and resume later if not the whole frame is available. 
- Also ensure that the next frame starts with a proper sync word.

Fixes #598.
2019-10-01 10:15:58 -07:00
KongQun Yang a86a697d8d Add more loggings for GAPs
Fixes #474.

Change-Id: I32f097c8a0e8d3381a276e6a130cb888e3ddd7f6
2019-09-11 00:02:52 +00:00
KongQun Yang 3ec2975e36 Log socket error code on failure
Issue #643.

Change-Id: I8adfb9910e1e43294738abb7783a64645a4f42c3
2019-09-10 21:44:28 +00:00
Tomohiro IKEDA b8ee20df1d Improve ConvertToADTS function performance (#639)
Remove the extra data copying.
2019-09-10 13:15:17 -07:00
KongQun Yang 9029e2d34f [HLS] Fix live chunks not deleted with $Time$ in segment template
Store and use the segment start time in the original time scale to
delete old segments, instead of storing it in seconds, as the segment
file name is generated using the time with the time scale.

Fixes #625.

Change-Id: I7524d597b1ffc081dd1399d6fb3ea47c13502881
2019-08-20 17:43:46 +00:00
KongQun Yang faa9a3ea68 [HLS Packed Audio] Truncate timestamp to 33 bits
Fixes #629.

Change-Id: Iadbbb28de051bf6b8b08561c152a3c1c2014aa80
2019-08-08 14:31:05 -07:00
KongQun Yang edd776eea2 Move DerivePixelWidthHeight to video_util.cc
Change-Id: I14df8b39fb58078635f08377f4177a45e341be79
2019-08-05 11:56:20 -07:00
KongQun Yang c257113e08 Support parameter sets in stream (avc3, hev1 etc)
- Parses parameter set NAL units in the samples.
- Calculate pixel width and height from track width and height.

Fixes #621, #627.

Change-Id: Ic1e120dccbd220b01168f7bf4effeaa43f95b055
2019-08-05 17:38:34 +00:00
Tomohiro IKEDA f810fea0ef Cleanup condition on `bind` error (#624) 2019-08-01 17:32:28 -07:00
KongQun Yang 78941394dd Add flag FLAGS_disable_peer_verification
To allow disable peer verification.

Issue #623.

Change-Id: I0781d10dea3ef6c92f0139aa1fa4949449c5da36
2019-07-22 16:33:32 -07:00
Tomohiro IKEDA 2c51dcc601 Code cleanup: no "if return else return" (#611)
- Unify code format
- Low nest level
2019-07-15 11:03:42 -07:00
KongQun Yang 3c26dfbd53 Estimate target duration in bandwidth calculation from initial blocks
We used to use the target segment duration provided by the user.
Unfortunately that does not work for iframe only playlist which
the target duration is effectively equal to the GOP duration.

In the new approach, we estimate the target duration from the initial
few blocks (10 blocks right now).

Fixes #610.

Change-Id: Ie8bf943e157149ca7ed3b9382fe0a1088d0774e2
2019-07-11 17:45:55 -07:00
KongQun Yang 15a4f0553c Add a new utility function for XmlNode
Add AddDescriptor function to add new descriptor nodes with schemeIdUri
and value fields.

Change-Id: I423e642939fdef99764a67da74d4efd4d32aefe8
2019-07-01 20:29:11 +00:00
KongQun Yang 796974d2a1 [DASH] Support custom Accessibility and Role elements
Add dash_accessibilities stream descriptor, which is a semi-colon
separated list of accessibility_scheme_id_uri=value. It is optional.

Add dash_roles stream descriptor, which is a semi-colon separated
list of strings. It is optional.

Closes #565.

Change-Id: Idb1c20bb410fdd016db07e11fe507c102a3dd8ea
2019-06-13 15:43:32 -07:00
KongQun Yang 0a2b43939c [HLS] Replace hev1 in codec with hvc1 and avc3 with avc1
And also dvhe with dvh1.

Apple's specification does not recommend video formats with the
parameter sets stored in the samples.

It also fails mediastreamvalidator checks and some Apple devices /
platforms refused to play.

See https://apple.co/30n90DC 1.10.

Replaced with the corresponding formats with the parameter sets stored
in the sample descriptions instead.

Fixes #587.

Change-Id: Ic5d3f6fde115b1d09d1dcac32cef5fe0ad246aa0
2019-05-22 13:17:27 -07:00
KongQun Yang adc3c804a9 Support absolute file path in playlist_name
Fixes #585.

Change-Id: Icd0bc97a0b210c22a2dab716542d993a69d3d081
2019-05-13 18:13:37 -07:00
KongQun Yang ac616f36e4 SimpleHlsNotifierTest: Use value parameterized tests for rebase tests
Change-Id: Ie734624f6335b01b9bf989e1432ddb4fdf2e4b8b
2019-05-07 23:55:23 +00:00
KongQun Yang 4b8e9a662f Fix problems that target duration is not set in mpd/hls params
We have logics in bandwidth calculation to ignore segments that is
smaller than half of target duration. The logic does not have any
effect right now as the target duration in mpd/hls params is always
zero.

This change will set target duration in mpd/hls params, thus it can fix
part of issue #581 as the last segment which is less than half of
target duration.

Issue #581.
Fixes #498.

Change-Id: Ieb2dbf4da9fc72a7b9de802cda4294f1954d29b4
2019-04-30 22:41:14 +00:00
KongQun Yang b85e5c9368 Use segment duration in buffer depth calculation
Segment start,end time was used previously, which could result in
problems if there are discontinuity in the streams. E.g. if the
stream has timestamp, 10000, 10001, 10002 and then next segment
comes in with timestamp 1. With the previous logic, all the segments
would remain in the time shift buffer until after 10000 segments
even with a small time shift buffer depth of 10.

This could also happen when timestamp wraps around, which could
happen during long time of live streaming.

This change will also be useful to support multi-period live DASH.

Fixes #563.

Change-Id: Ie078d76c6e4af13ade9ad46191c8e3529069ed4d
2019-04-17 22:47:10 +00:00
KongQun Yang fa2c4409a6 Add a flag --video_feature for Widevine
Change-Id: Id9ab958add1239972a4f94faf5e65cffe64444be
2019-04-16 07:55:08 -07:00
KongQun Yang fa7a6d967a Allow CMAF file extensions
Extensions cmfv, cmfa, cmft are now supported and recognized as
CONTAINER_MOV.

Fixes #574.

Change-Id: I728feefaba91f862966af49c780bbac8068722f2
2019-03-26 12:27:46 -07:00
KongQun Yang 26bc55503d Allow reserved NAL units in H264/H265
This is needed for Dolby Vision as Dolby Vision uses NAL unit type 62
to carry private information.

Issue #341.

Change-Id: Ib3f06d8f36ef3d89c33162dd74c012a0c3a805e5
2019-03-18 17:40:25 -07:00
KongQun Yang d850befb72 Refactor and Cleanup Descriptor classes
- Define BaseDescriptor and generic read / write operations.

- Define descriptors: ESDescriptor, DecoderConfigDescriptor,
  DecoderSpecificInfoDescriptor, SLConfigDescriptor.
  DecoderSpecificInfoDescriptor and all other descriptors can now
  handle arbitrary length size, not limiting to 64 byte for
  DecoderSpecificInfoDescriptor, which was placed to limit
  ESDescriptor length size to one byte.

- Now DecoderConfigDescriptor is able to handle reading and writing
  of all fields including buffer_size_db, which was not handled
  earlier.

Fixes #536.

Change-Id: Ia8a775f8bf6e90e3343a85f0e643bc44cd017c7a
2019-02-27 22:26:10 +00:00
KongQun Yang fcfc843a2e Use IV from Widevine key server if available
Fixes #555.

Change-Id: Ic077f97884a0c3d26159cd44791298bdd400068d
2019-02-27 22:17:21 +00:00
KongQun Yang 57046be126 Make packager_test.py work with python 3.5
Addresses binary/str conversion problems like
'can't use a string pattern on a bytes-like object'.

With this change, packager_test.py will work with any version of python
after python2.5.

Fixes #553.

Change-Id: I02066942e4bcdddc1db1daf761abab4cc46169a9
2019-02-13 19:07:56 +00:00
KongQun Yang de534f8550 Make packager_test.py work with python 3.0
Use logging instead of print.

Fixes #553.

Change-Id: I46b9a5bb9bb5d4cb03ddd94163905aebc4b4e9dd
2019-02-01 22:52:59 +00:00
KongQun Yang 72c4797a59 Update pssh-box.py to remove external dependencies
With the update, the script needs to be launched from
out/{Debug,Release} directory.

Also updated docs to make it clear how to use the tool.

Fixes #538.

Change-Id: I37b71afc33e3b73ff5232e43d79c52ffa5859d57
2019-01-31 00:49:12 +00:00
srebrnyp 22af5533b1 Add crypto_period_seconds to Widevine key request (#545)
Add crypto_period_seconds to Widevine key request

When using key rotation with Widevine DRM, a key server has to know
the duration of crypto period to relate generated keys to the media
playback time. This helps the server to provide relevant keys to
a client during license request.

Closes #544.
2019-01-24 10:39:54 -08:00
KongQun Yang 6d6db76c80 Retry file deletion if it fails
The file deletion could fail if it is still held by the web server.

This CL adds retry logic to retry the deletion.

Closes #533.

Change-Id: Ib42ed8db11f32897a29e3b58c1be89d05f5dd034
2019-01-02 15:23:27 -08:00
KongQun Yang 3f7ecd4e29 Workaround extra AUD in the access unit
VLC seems to generate access units with extra AUDs. In #526, the below
sequence is seen:

  AUD | SPS | PPS | SPS | PPS | AUD | SEI | SEI | SEI | IDR_SLICE

Previously we exit early when seeing AUD, which results in delayed
processing of the access unit.

The behavior is changed to continue processing the following NAL units
to workaround the content issue.

Closes #526.

Change-Id: I80f571c0711c6db1337eb393fce36fae5432b6c5
2018-12-15 00:32:06 +00:00
KongQun Yang 89611a526b [HLS] Support audio only master playlist
Generate an audio only master playlist if there are no videos and
subtitles.

We do not support mixing audio only EXT-X-STREAM-INF with video
EXT-X-STREAM-INF right now.

Fixes #461.

Change-Id: I999b335ad7abbe183ffcb0f5d471948977c2772f
2018-12-13 23:52:35 +00:00
KongQun Yang cd7640a5bd Support trick play with Ad cues
Fixes #528.

Change-Id: I558285a2fae3d2048ef7cefabcd4761e35be47a8
2018-12-13 00:27:11 +00:00
KongQun Yang 9819adf9d6 Fix error code message for trick play error
Issue #528.

Change-Id: Ib0752960db94910038290b235f64b360cd4f2f00
2018-12-13 00:26:55 +00:00
KongQun Yang d97e531465 Set output directory permission appropriately
The new directory permission is set to the permission of the last
existing directory in the file path. If none of the directory exists,
it is default to 0755.

Previously we use base::CreateDirectoryAndGetError(), which always sets
the new directory permission to 0700, which is not what we want.

Fixes #499.

Change-Id: Iee9429d5e63ada9588f74ff20d3cce28a1a6437b
2018-12-11 23:17:15 +00:00
KongQun Yang 492f55a018 Use upper case for Marlin uuid
This is required by Marlin although it is against uuid specification
(ITU-T X.667).

Issue #525.

Change-Id: I1592d6abe24ae09bfbb2f80931a330ee6fd61eb5
2018-12-05 13:03:25 -08:00
KongQun Yang c5fa32f0eb Return an error when seeing duplicated outputs
Fixes #497.

Change-Id: Ic3f5352b6774fbd488e6d688df4c8a5053732549
2018-11-27 22:38:48 +00:00
KongQun Yang 4b97a6d8a2 Add support for --default_text_language
It allows users to override the default language for text tracks.

If not specified, --default_language applies to both audio and text
tracks.

Issue #430.

Change-Id: I86a9baba2072be27b6661fa7b65a8bc8b6adb3cc
2018-11-26 13:42:58 -08:00
KongQun Yang 273ab09f05 Support HLS characteristics
Add hls_characteristics stream descriptor, which is a colon or semi-colon
separated list of strings. It is optional.

Fixes #430.

Change-Id: Ifcf79316e68768ff065891933de565cd0ff32ec4
2018-11-26 20:02:43 +00:00
KongQun Yang 74df8d30cc Exclude short segments from peak bandwidth computation
https://tools.ietf.org/html/rfc8216#section-4.1
The peak segment bit rate of a Media Playlist is the largest bit rate
of any contiguous set of segments whose total duration is between 0.5
and 1.5 times the target duration.

Fixes #498.

Change-Id: I1f28972b9cc5977735e47906bdcd88ba3942db5a
2018-11-26 20:02:09 +00:00
KongQun Yang 4c6059be78 Fix mpeg-ts demuxing with AC-3/E-AC-3
kFrameSizeCodeTable rows are ordered by 32kHz, 44.1kHz and 48kHz,
which is the reverse of fscod (48kHz, 44.1kHz and 32kHz).

Also updated unittests.

Fixes #487.

Change-Id: Icb0afb8bb895afde0028eee05b403bc85bf7b538
2018-11-20 22:33:40 +00:00
KongQun Yang ae3da3772e Use lower-case for Marlin ContentId
This is required by Marlin specification. Also added unittests.

Issue #381.

Change-Id: Icae1213db4c0915720ed07e6b2bb768fa9156a5c
2018-11-20 19:04:33 +00:00
KongQun Yang db3ed544f8 Add the logging for 'Container not supported' error
Dump the first 512 bytes of the buffer if container is unknown. This
can help us find out what the actual container is; and fix the
container detection bug if there is.

Closes #505.

Change-Id: I4a8fe5954d0419ef2ccbb9067ec2e9ffe1da417e
2018-11-09 10:26:33 -08:00
KongQun Yang 53aa775ea4 Omit all optional fields in AV1 codec string
The spec requires the optional fields to be mutually inclusive
(all or none).

Issue #453.

Change-Id: I6d62bb862957abe7a3517058510f614995a92dd9
2018-10-12 13:20:11 -07:00
KongQun Yang 4b19905bc2 Support subsample encryption in AV1
Closes #453.

Change-Id: I68e46fb83cbf7e62a19fa83698cb66bfc0acd98d
2018-10-11 11:35:00 -07:00
KongQun Yang 5c4d930465 Move subsample extraction out of EncryptionHandler
Created SubsampleGenerator to generate subsamples.

This is part of the EncryptionHandler clean up to make it more modular
and testable.

Change-Id: I6f4076b057027c72335beb3cbf1965341eb18031
2018-10-11 10:38:43 -07:00
KongQun Yang acaa6b9b3b Move encryptor setup out of EncryptionHandler
Created EncryptorFactory to set up the encryptors.

This is part of the EncryptionHandler clean up to make it more modular
and testable.

Change-Id: I839bcd8a84fa873396360d67afb540fef1345673
2018-10-10 19:27:28 +00:00
KongQun Yang 8d11e5ea64 Support Marlin DRM signaling in DASH
Only Marlin Adaptive Streaming Specification – Simple Profile is
supported.

Two additional updates:
- Remove FairPlay ContentProtection element from DASH mpd as FairPlay
  does not define a signaling in DASH.
- Updated end to end test to include all DRMs we support.

Closes #381.

Change-Id: Id12269b471ea34983b782cbd92f687332292ef59
2018-10-01 20:22:58 +00:00
KongQun Yang fc0c5ddf0d Implemented AV1 bitstream parser
Implemented according to bitstream spec at
https://aomediacodec.github.io/av1-spec/.

It will be used to do AV1 subsample encryption later.

Issue #453.

Change-Id: I84d8a2a780d95f2c9f430ee598838b97474cc0af
2018-09-28 18:45:44 +00:00
KongQun Yang 19f80d8478 Put namespace URIs in DASH mpd only if needed
Change-Id: I31284b665599a8ee8f0b1aa11b58d6797dbe2884
2018-09-25 15:45:48 -07:00
KongQun Yang 08aa9b6b2b Remove FairPlayPsshGenerator
This was introduced earlier to indicate FairPlay protection system. But
in fact, it is sufficient to just use the system id for the indication.

- Also updated various parts of the pipeline to support empty PSSH.
- Added an additional FairPlay end to end test using fMP4.

Change-Id: Ica48b7b5235e9a2b5a7f722bcd0fc1ef2073ac13
2018-09-21 00:49:35 +00:00
KongQun Yang 42083d205d [DASH] Fix TTML text input passthrough (regression)
Note that TTML in ISO-BMFF is not supported yet.

Also updated packager_test.py:
- Added a test using TTML passthrough.
- Computed output extension from input extension unless output_format
  is specified.

Fixes #478.

Change-Id: Ia917fc4ed3c326782791ed67601fba02ea28b11d
2018-09-19 23:27:48 +00:00
KongQun Yang 5a912815c1 Move protection system Ids to protection_system_ids.h
Change-Id: Ia22b89c38b3b1ff7ead05f8484e15edef6218953
2018-09-17 15:29:53 -07:00
KongQun Yang cb77b65117 Rename RawKeyPsshGenerator to CommonPsshGenerator
Change-Id: I59f9156ae0f13f04ba846806c661292f29339945
2018-09-17 15:10:59 -07:00
Denis Akhmetzyanov 31fc2f5135 Clear up condition in AesPatternCryptor (#476)
The condition was the same in meaning, but a bit confusing in syntax.
2018-09-13 14:04:11 -07:00
KongQun Yang 31e5f129b5 Fix incorrrect segment name with $Time$ in segment_template
The time for the previous segment was used when generating the segment
name. This resulted in the first segment being overwritten and
mismatching manifest and media files. It led to playback problems.

Issue #472.

Change-Id: Ia8130ce261585e1a2ede83b26de3e32508de087f
2018-09-13 00:56:28 +00:00
KongQun Yang d0978b3937 Compute and set VP9 Level if it is not already set
The VP9 level is computed when the container is missing a codec config
or if the level is missing from the codec config.

This fixes VP9 in ISO-BMFF files generated by FFmpeg v4.0.2 or earlier
which does not have level set in the codec config.

Fixes #469.

Change-Id: I685bfd48be16ee6b2209da1c3173f7d6bb02b36a
2018-09-13 00:37:30 +00:00
KongQun Yang 0709db4bbc Add support for AV1
Implemented per AV1 Codec ISO Media File Format Binding at
  https://aomediacodec.github.io/av1-isobmff/
And AOM AV1 codec mapping in Matroska/WebM at
  https://github.com/Matroska-Org/matroska-specification/blob/av1-mappin/codec/av1.md

Note that AV1 specific boxes are not supported in this CL, i.e.
AV1 Forward Key Frame sample group entry 'av1f', AV1 Multi-Frame
sample group entry 'av1m' etc are not supported. These boxes are optional.
We will add support later if they are useful to the clients / players.

Encryption is not supported yet.

Issue #453.

Change-Id: I630432d0a9bf82d263ffaf40e57f67fc65eee902
2018-08-31 19:16:04 +00:00
KongQun Yang 86b10b6316 Fix pattern encryption when applying to patterns other than 1:9
We used to skip all the remaining bytes if the size is less than
|crypt_byte_block| blocks.

This interpretation is incorrect. We should only leave the last partial
16-byte block un-encrypted.

Change-Id: I4f09600efa52e2fdf4d0b661dfc418dcb675f9f6
2018-08-31 19:15:43 +00:00
Aaron Vaage 60df64705b Created Test Handler CachingMediaHandler
Renamed "FakeMediaHandler" to "CachingMediaHandler" so that it
is easier to differentiate from "FakeInputMediaHandler". It will
be used as the single method to verify media handler output.

This is part of an effort to find a cleaner way to test media handlers.

Change-Id: Ie391fe23ee3389d13b012ae3093744a453106c19
2018-08-31 02:42:34 +00:00
KongQun Yang 33792ca2da Workarounds TS contents with dts moving backwards
Negative duration is not allowed, so set the duration of that sample to
an arbitrary small value in case it is needed to decode future samples.

Issue #451.

Change-Id: I9250d71d163f769ea2657d56e108b6dbd583de67
2018-08-28 20:25:35 +00:00
Aaron Vaage e071710fa9 Adding Missing "// namespace"
Change-Id: I7bdb5841a8b22c59d97f120f8d83bddcc77858cb
2018-08-27 17:19:31 +00:00
KongQun Yang 40a3b42980 Fix pattern signaling in seig for key rotation with cbcs
Closes #460.
Bug: 112769382

Change-Id: Id2277edf9ac1ca637354f3a585666ad139ed8ee2
2018-08-24 23:20:06 +00:00
KongQun Yang 9b655189cf Disable bundled_binutils and bundled_gold on Linux
Keep bundled binutil scripts but not downloading actual binaries by default.

Automatic downloading of binutils has been causing problems for some users:
see #164, #412, #440.

Using bundled binutils helps reduce linking time, but packager codebase is
relatively small, so the gain is not significant.

Local testing shows that the full build time increases from 1m42s to 1m50s, i.e.
an increase of about 8s, or ~8%.

User can still enable the usage of bundled binutils by running
'python src/packager/third_party/binutils/download.py' and set
'linux_use_bundled_binutils' and 'linux_use_bundled_gold' to 1 in GYP_DEFINES.

Change-Id: I7ecae2333861f41054f957d0a6081dae948167bd
2018-08-24 21:14:19 +00:00
KongQun Yang e5b8b3ec64 Add support for seek preroll in AAC and other audio codecs
Closes #452.

Change-Id: I0f648c4fa6c861540b050a5b4e9878987c8383e5
2018-08-23 18:58:04 -07:00
KongQun Yang f49b89280c Support STYLE and REGION in WebVTT
Note that STYLE and REGION are not supported in mp4 container due to
spec limitation as 14496-30:2014 does not specify a way to signal
styles/regions inside mp4.

Closes #344.

Change-Id: I05c14df916f7b2c7ca4364ee9407e0eda4dc7a3f
2018-08-20 14:12:07 -07:00
KongQun Yang 715ed939f1 Add instructions to build on Alpine Linux
- Also fixed compilations in Alpine Linux and other flavors of Linux.
- Added container versions in docker files to always use a verified
  version.

Closes #164.

Change-Id: I949a8709e4d70c49129c9c2e8608dd78193d964c
2018-08-17 20:46:11 +00:00
KongQun Yang 451406ad3f Update DRM documentations
Fixes: #245.
Fixes: #306.

Change-Id: Ib847f5cfbf01b98f7a7e088dfcbc4d25cbbc15f2
2018-08-15 17:18:57 -07:00
KongQun Yang 04a4275a44 Not generating Legacy Widevine HLS signaling by default
Configurable under --enable_legacy_widevine_hls_signaling, off by
default.

When it is enabled, do not fail if provider or content_id are missing,
but log a warning instead.

Bug: 112268769.

Change-Id: I2531aa7474d2818700b90fa0679b49891bb935ef
2018-08-14 23:00:04 +00:00
KongQun Yang 5602050ba4 Set default clear lead to 5 seconds
Change-Id: Ic9ec564659c9df983c8dd885a0cafd45d20cb2fd
2018-08-14 22:59:37 +00:00
KongQun Yang 8612798de1 Change --additional_protection_systems to --protection_systems
Issue: #245.

Change-Id: Ib7da3b874207623e3ee0b1a942ecb2509e750669
2018-08-14 22:12:55 +00:00
KongQun Yang fd41ef0032 Properly handle failures when using PlayReady key source
Change-Id: I0a50ae67fcde1fa4a99b91ad7c2642bbfc90b73a
2018-08-14 21:17:45 +00:00
KongQun Yang 6f66132aa9 Support Widevine PSSH with protection scheme generation
Issue #245.

Change-Id: Ieabdd3cdc55eb5bd4b7a145c9d041cc918101f18
2018-08-10 00:00:21 +00:00
KongQun Yang db076d6892 Support Fairplay in --additional_protection_systems
Issue: #245.

Change-Id: I15187c1d3463534bf5e11ff97032311bb1d0c3bf
2018-08-09 23:59:40 +00:00
KongQun Yang 2a80c6773a Clean up PsshGenerators
Change-Id: I0940bd5a2a0a5af175088a15890ddd82602d0c7f
2018-08-09 23:59:04 +00:00
KongQun Yang 2fee1e673b Set default --io_block_size to 64K
--io_block_size determines the buffer size for each read/write in
ThreadedIO.

A big io_block_size does not help much as long as --io_cache_size
is big enough.

Instead, it may cause problems. For example, Linux pipes block until
reading io_block_size number of bytes, which causes a large delay
when reading audio streams.

Change-Id: I5bdd3d61388579c7e8647cdab3152135a40a752b
2018-08-09 22:24:43 +00:00
KongQun Yang 36a7c7d935 Adjust timestamps in fMP4 if there is an initial composition offset
In some ISO-BMFF files, there is an initial non-zero composition offset,
but there is no EditList present.

This is against ISO-BMFF spec recommentation [1] and we believe in most
cases it is just missing the EditList.

[1] 14496-12:2015 8.6.6.1
It is recommended that such an edit be used to establish a presentation
time of 0 for the first presented sample, when composition offsets are
used.

Issue: #112.
Change-Id: I178d5ec9d8c294c9f70aac4f4dd6254c824e2255
2018-08-09 22:03:23 +00:00
KongQun Yang 0fe31423cb Multi-DRM flag refactoring
- Added flag --additional_protection_systems to specify multi-DRM
  options.
- Deprecated old multi-DRM flags: --generate_widevine_pssh
                                  --generate_playready_pssh
                                  --generate_common_pssh

Issue: #245.

Change-Id: If926bc9d481e941aa2269b6672bf2ba5411c3a50
2018-08-09 22:01:46 +00:00
KongQun Yang b4e827e01b Make sure TempFilePath always generate unique file path
Previously it is possible that the same file path is generated when
the function is called consecutively in the same thread.

The problem can be re-produced in Windows. Does not seem to be
re-producible in Linux and Mac.

Fixes #448, #449.

Change-Id: Ia0163492e3494eba00f56f4d356aa1010b9660cc
2018-08-08 17:33:01 +00:00
KongQun Yang d932153dd7 Make MemoryFile thread-safe
- Also make it explicit that MemoryFile does not support opening an
  already open file. An error will be returned when trying to open an
  already open file. Previously the code may crash with memory problems.
- Also updated packager_test to use different test directories for
  different tests.

Fixes Appveyor crash due to memory corruption: #449.

Appveyor may still fail but will contain a meaningful error logging.

Change-Id: Ibc9346ef7f301e416a4a09f120bca56504c939d8
2018-08-08 17:32:46 +00:00
KongQun Yang 416051ae65 Avoiding segmentation fault on streams without samples
An informational message is logged instead.

Fixes #446.

Change-Id: Ia3a79a16b3bdbabd5d56facf9bf011f29c9b1533
2018-08-02 17:53:17 +00:00
KongQun Yang 64c3b4c558 Remove base dependency from packager_test.cc
So that packager library is used in the same way as how it is used
in real world.

Change-Id: I38a59f4b1153edd048f078df4447cd9c0464caa5
2018-08-02 17:41:05 +00:00
KongQun Yang ca810e06d5 Order trickplay outputs in trickplay factor ASC order
This also ensures that it does not violate std::sort() requirement on
strict ordering, which is enforced in gcc/g++ though not in clang.

std::sort() strict ordering requirement:
std::sort() need a comparator that return true iff the first argument is
strictly lower than the second one. That is: must return false when they
are equal.

Change-Id: I781cf4ed4125fcad212eba5430a264f3a3d71c16
2018-08-01 15:06:21 -07:00
KongQun Yang 32e3ff3e25 Set default --segment_duration to 6 seconds
This is recommended by Apple and other content providers:
https://apple.co/2uTTAc4

- Set default --clear_lead to 12 seconds, i.e. about 2 segments.
- Set default --fragment_duration to 0 so fragment (sub-segment) is not
  generated by default.

Change-Id: Ie6ec3ab6f0ce973547989c663a92b637a2fdc47c
2018-07-31 20:49:43 +00:00
KongQun Yang bd98436241 Normalize crypto_period_index to 0 for negative timestamp
It is possible to see a negative timestamp if the input mp4 file
contains EditList.

Also increase the queue size for EncryptionKey to be able to handle
smaller crypto_period_duration during testing.

Change-Id: I68278bf482d6662e771d9b80f4d5409605065aac
2018-07-31 12:56:33 -07:00
KongQun Yang 51d39d96a1 Add offset to tranport streams (MPEG2-TS, HLS Packed Audio)
Configurable with --transport_stream_offset_ms.

This is needed to compensate for possible negative timestamps in
inputs, which could happen on ISO-BMFF with EditLists.

Issue #112.

Change-Id: I0fce8766c9df2911b9bb859c1e54052a8ed2abfb
2018-07-26 23:20:21 +00:00
KongQun Yang 9a55d4033f Adjust timestamps in mp4 if there is an initial composition offset
In some ISO-BMFF files, there is an initial non-zero composition offset,
but there is no EditList present.

This is against ISO-BMFF spec recommentation [1] and we believe in most
cases it is just missing the EditList.

[1] 14496-12:2015 8.6.6.1
It is recommended that such an edit be used to establish a presentation
time of 0 for the first presented sample, when composition offsets are
used.

Issue: #112.
Fixes: b/110782437.

Change-Id: I23d33810ce536b09a1e22a2644828d824c1314f5
2018-07-26 23:20:21 +00:00
KongQun Yang 40ea1286b9 Add support for EditLists in ISO-BMFF
- EditLists in input files are parsed and applied to sample timestamps.
- An EditList will be inserted in the ISO-BMFF output if
  - There is an offset between the initial presentation timestamp (pts)
    and decoding timestamp (dts). Chrome, as of M67, still uses dts in
    buffered range API [1], which creates various problems when buffered
    range by pts does not align with buffered range by dts. There is
    another bug in Chrome that applies EditList to pts only [2]. This
    means that we can insert an EditList to align pts range and dts range.
  - MediaSamples have negative timestamps (e.g. for Audio Priming).

You may notice the below change on some contents:
- Some media duration is reduced by one or two frames. This is because
  EditList in the input file was ignored in the previous code, so video
  streams start with a zero dts and a non-zero pts; the smaller of dts
  and pts was used as the starting timestamp (related to the earlier
  workaround for Chrome's dts bug), so the calculated duration was
  actually a bit larger than the actual duration. Now with EditList
  applied, the initial pts is reduced to zero, so the media duration is
  also reduced to reflect the actual and correct media duration.

It may also result in negative timestamps in TS/HLS Packed Audio, which
will be addressed in a follow up CL.

Fixes #112.
Partially address b/110782437.

[1] https://crbug.com/718641, fixed but behind MseBufferByPts.
[2] https://crbug.com/354518. Chrome is planning to enable the fix for
    [1] before addressing this bug, so we are safe.

Change-Id: I59317740ad3807ca66fa74b3a18fdf7f32c96aeb
2018-07-26 23:20:21 +00:00
Yohann Connell f331f18f0e Removing dependence on base file atomic_sequence_num.h
This part of issue #346.

Change-Id: If03736b688a0bf95aaf09ed3cfd5d5a0134e1c44
2018-07-24 21:22:50 +00:00
KongQun Yang 335a659fab [DASH] Fix possible incorrect segmentAlignment in static live profile
DASH live profile with static MPD was incorrectly handled in the same
way as live profile with dynamic MPD, i.e. by assuming the synchronized
Representations, which is incorrect.

It can be easily re-produced in multiple period outputs, i.e. with Ad
cues. It may happen with regular contents as well, due to race
condition, though with a much lower chance of occurring.

Fixes #435.
Bug: 111359775.

Change-Id: I7de087f5dd8602b4c4e35cb697d589fa3699e8a5
2018-07-24 18:48:01 +00:00
KongQun Yang 9a26ec1e83 Ignore extra Ad cues at the end of the stream
They will result in empty DASH representations, which is not spec
compliant.

For text, if the cue is before the max end time, it will still be
dispatched as the text samples intercepted by the cue can be split into
two at the cue point.

Bug: 111359775.

Change-Id: I55c2025c4e9d64c88e6a685c0cf3024a0cc4a6d8
2018-07-24 18:46:30 +00:00
KongQun Yang 86a86ce954 Return an error with '$' in stream output for WebVTT
WebVTT output with one file per Representatin per Period is not
supported yet.

Bug: 111359775.

Change-Id: I63f8dbbd65e6e286778474175d33f337f2a758ae
2018-07-24 18:45:44 +00:00
KongQun Yang 26997bb361 Fix flaky test in packager_test.py
MPD cannot be validated right now since we do not generate deterministic
mpd with multiple inputs due to thread racing.

Exclude mpd comparison in this case.

Change-Id: I03b68b4969a39e20927c8a9b1475f72493682696
2018-07-23 22:21:18 +00:00
Yohann Connell ec63c53ed5 Removing dependence on base file atomicops.h
This part of issue #346.

Change-Id: Iab685145d10d6e6c99ff666e08bca3c36b6d5a66
2018-07-23 22:19:29 +00:00
KongQun Yang ff5945688d Generate DASH IF IOP compliant mpd with mpd_generator by default
I.e. enable --generate_dash_if_iop_compliant_mpd in mpd_generator by
default.

It was enabled in the main packager binary in v1.6.1.

Change-Id: Icfb19758c52c107e8ab17d3fb581923fa291cc0a
2018-07-23 22:11:00 +00:00
KongQun Yang 308b92d16e [WebVTT] support cues without payload
WebVTT cues without payload may not carry meaningful information, but it
is allowed by WebVTT specification [1]. It could also be useful
sometimes, e.g. to signal the time progression in live case.

Fixes #433.

[1] https://www.w3.org/TR/webvtt1/#types-of-webvtt-cue-payload

Change-Id: I9e31f4a3789cbdafb7667b64f4019834190ecfc0
2018-07-17 17:07:53 +00:00
KongQun Yang 83f29ff964 packager_test.py: clean up output filename logic
Change-Id: I8df03d6ff6af0c621a7863d19d06e98b93fcb372
2018-07-16 23:06:08 +00:00
KongQun Yang 772400e2d5 Cleanup diff comparison in packager_test.py
Change-Id: I30ef75329060e15d54fdfa5fac44d499e3a6925a
2018-07-16 23:06:01 +00:00
KongQun Yang 71072d4e6d Combine some DASH/HLS tests into one
This saves some testing time and also make it easier to compare
DASH and HLS test results.

Change-Id: Ia4bdb39f1f5ef7ee7b3f8f37f83d7490109380c2
2018-07-16 14:59:16 -07:00
KongQun Yang b4ae6561f8 Cleanup packager_test.py
- Support decryption verification in _CheckTestResults
- Allow diff_files in _CheckTestResults
- Update all functional tests to use _CheckTestResults

Change-Id: I3f9c02f35808eba787becf9b1e5c1ce9238f943e
2018-07-16 19:13:02 +00:00
KongQun Yang 5dd21179ec Do not use harmonic mean in bandwidth calculation
Instead, caclulating average bandwidth by dividing the sum of the
sizes of every segment by the sum of the durations of every segment.
This aligns with the requirement in HLS spec:
https://tools.ietf.org/html/draft-pantos-http-live-streaming-23 4.1.

BandwidthEstimator is also simplified to handle all blocks only.

Fixes #361

Change-Id: I89e7d415a841f4d4048f199de8dae7ffa250467b
2018-07-12 10:46:47 -07:00
KongQun Yang 99a2ad03af [HLS] Support AVERAGE-BANDWIDTH
Issue #361

Change-Id: Id8eb8283675cba5ec7234d13c4ac235f34e3bec9
2018-07-12 10:43:49 -07:00
KongQun Yang f97413bf6e Suppress C4819 in Windows
There are non-ASCII characters in comment section of some source
code, which is causing compilation problems on some systems with
a codepage that cannot represent these characters.

Fixes #419.

Change-Id: I20d68a201263d515290ee440b52c5354b739099a
2018-07-12 17:10:39 +00:00
Aaron Vaage a510d3aa38 Print Error and Ignore Text Samples With Bad Times
Before we had an assert that would catch if a sample had an
invalid times, however input may have bad times.

We did have a message if we saw a sample with a duration equal to
zero. This expands that check to check if the time is valid in
general and will ignore any sample that is not valid.

Fixes #425

Change-Id: I9774bfbdbd401f3016d2c345665b9973d1889db7
2018-07-09 15:25:10 -07:00
KongQun Yang 1742e03471 Drepcate --num_subsegments_per_sidx
This flag was designed for two purpose:
- Grouping fragments into subsegments, achieving three level hierarchy:
  segment < subsegment < fragment.
- Indicate whether to generate 'sidx' box in media segments (when the
  value is set to a negative number).

There are no practical use case for the first purpose. Removing it to
simplify the code and reduce the confusion.

Introduce another flag --generate_sidx_in_media_segments for the second
purpose.

Change-Id: I4be7cd42662fb324c1158b978e05768ee49dd048
2018-07-02 21:59:14 +00:00
KongQun Yang f089d1d0d4 Deprecate --mp4_use_decoding_timestamp_in_timeline
It was implemented to workaround Chromium's DTS
https://crbug.com/398130, but the workaround does not really work in
all situations.

Remove it now as we already have another workaround available.

Change-Id: I291f559d78120fb743a6679b7d927e5bbc5b6b4e
2018-07-02 21:59:01 +00:00
KongQun Yang 571ee24f3e Use PTS instead of DTS in ChunkingHandler
DTS was used in ChunkingHandler. As a result, SegmentInfo contained
timestamp in DTS. MP4Muxer has a logic to change SegmentInfo to use
PTS but not in other muxers.

Benefits of using PTS in ChunkingHandler:

- De-dup the redundant logic in MP4Muxer
- Ensure consistent behavior in different output containers
- Consistent with other timestamps, e.g. Ad Cue timestamps

Issue #413

Change-Id: Ib671badf144e0c0866d60f4ff0ac0cbbdd33817e
2018-07-02 21:58:45 +00:00
Aaron Vaage 5f072e3b08 Start Segments At First Sample in Text Chunker
We always assumed that text stream started at zero in the text chunker.
This meant that if the text stream started later than zero (like in a
live stream) we would generate a lot of empty segments.

Instead the text chunker will assume that segments should be adjusted
to align with multiple of segment duration. The text chunker will assume
that an earlier component in the pipeline (i.e. text padder) will ensure
that the first sample has the time that we want to start segments at
(even it needs to add an empty sample).

Issue #416

Change-Id: Ie45844354d6e9448787cae896841b5ab31721ed6
2018-07-02 17:57:10 +00:00
KongQun Yang f21d93dd65 Clean up difference comparison in representation.cc
Change-Id: Ibde83d1b8b2f644899f93790978d906dba5d4c14
2018-07-02 17:48:17 +00:00
Aaron Vaage 1600909c4b Don't Always Start Text At Time Zero
Previously, the text padder media handler would assume that text always
started at time zero. This would work for VOD but would result with a
large pad at the start of LIVE content.

To avoid this, the text padder will use a bias to test whether or not it
thinks the content starts at zero. Right now the bias is set to be 10
minutes, but will later be configurable with a command line flag.

10 minutes was used as LIVE content will have much larger values and VOD
content should have much lower values.

Issue: #416

Change-Id: I07af15a577392fb030e36f052085cd4e667700e8
2018-06-29 23:02:22 +00:00
KongQun Yang b4256bf040 [Cleanup] Use int64_t for time for consistency
Change-Id: I408f3fe7c98320be4e43ca2a5bcb9b22cc8a2012
2018-06-29 22:53:06 +00:00
KongQun Yang d1caa29c8d Disregard trailing null bytes when locating RBSP stop bit
This is a more faithful implementation of more_rbsp_data().

There could be trailing null bytes in NAL units. This isn't valid per
H264 specification, but the referenced bug includes a sample where the
PPS in the avcC record includes a trailing null byte.

Workaround the problem so packager does not fail.

A similar problem is workarounded in Chrome:
https://codereview.chromium.org/1107593004

Closes #418

Change-Id: I28cb8a9371945dc094f766c3e559d7a66859b451
2018-06-29 20:24:15 +00:00
KongQun Yang d3903fad19 Add buffer_size UDP file options
This allows UDP receive buffer size to be increased to avoid potential
packet loss result from receive buffer overrun.

Another related flag is --io_cache_size. buffer_size in UDP options
defines the UDP buffer size of the underlying system while
io_cache_size defines the size of the internal circular buffer managed
by Shaka Packager.

Closes #411

Change-Id: I57c843a88f13da546417dadc2a78df2bee0a00f3
2018-06-29 00:19:30 +00:00
KongQun Yang 7bc90004e0 Add IO Cache circular buffer full warning
Under VLOG(1).

IO Cache circular buffer full could result in UDP packet loss with UDP
inputs.

Related to #390 and #411.

Change-Id: Ia5636a70827978b5c2f71f6495256d758766632f
2018-06-29 00:19:14 +00:00
KongQun Yang 6b4a75b6ba Changed to use BandwidthEstimator in MediaPlaylist
Preparing for addressing #361.

Change-Id: I4b2e834948e681bc790efc61b63a24d44f70015d
2018-06-22 11:12:23 -07:00
KongQun Yang 418e741f7f [DASH] Fix potential text Segment Timeline not grouped
This happens when --allow_approximate_segment_timeline_ is set.

Fixes #417.

Change-Id: Idf938ad4e0f7788a00c7485b7eeda43358a94178
2018-06-22 00:45:00 +00:00
Aaron Vaage 0734ba998b Remove Old Cue Insertion Code
When we built the cue alignment media handler, we did not remove
the old solution.

This change removes all the code for the old solution.

Change-Id: I851b284c449c7d25aaabc2f55df5579ba7b5aad1
2018-06-21 18:47:04 +00:00
Aaron Vaage 5a9a49034b Merge Create and Dispatch in Cue Alignment Tests
Originally the create and dispatch of stream data in the cue
alignment tests were separate to improve readability. The idea was
to separate building each stream and dispatching the streams muxed
together would make it easier to understand the streams.

However, coming back to the code, this did not hold up as it took just as
long to understand the code. So merging the two together allows for the
code to be more concise.

Change-Id: I77f6bb67e7fb0ca7af0553c3baf07082770da74c
2018-06-21 18:27:01 +00:00
Aaron Vaage b5cdfee73f Update "One to many" example in Media Handler
In the media handler there is an example of what a one-to-many media
handler would be. It used the trick play handler as an example, but that
handler is now a one-to-one media handler. Changed the example to use the
replicator media handler.

Change-Id: I26908c6e27ea4a697a19c0fa0179c60842a449d2
2018-06-21 18:26:42 +00:00
Aaron Vaage 4408718b5b Move ChainHandlers to MediaHandler
Made ChainHandlers to MediaHandler::Chain so that it can be used in our
test code as well. After all it is a pretty helpful function.

Change-Id: I8d83ee184052cd9fa9b37f2741c96f3223d5ab48
2018-06-21 09:52:04 -07:00
Aaron Vaage eb2385491c Run clang-format over MediaHandler
Ran clang-format over media_handler.cc and media_handler.h so that
later changes won't update the formatting as much.

Change-Id: I2db4f9f4e8a66fca1e1418ab99b283a0e4a70e4c
2018-06-20 16:28:47 -07:00
Aaron Vaage 0efc7612ed Fixed Copy and Assign in MediaHandlerGraphTestBase
The copy and assign in MediaHandlerGraphTestBase referred to the wrong
types. This changes them to refer to the correct types.

Change-Id: I165c9a1da39b49adf41e7c35ae3e4a0b9ecfa838
2018-06-20 16:28:47 -07:00
Aaron Vaage d8830e3168 Remove "wvtt" from Master Playlist Codec String
Having "wvtt" in the codec string (in the master playlist) causes
errors on some older Apple products. As including it is optional,
we are opted to omit it to ensure support for all Apple products.

Close #402

Change-Id: Ib1072bcc26a3ff66e3a6d3204789c0c8c678d4db
2018-06-20 17:31:51 +00:00
Aaron Vaage b980cf3019 Reduce What We Check in Cue Alignment Tests
Reduce which variables we check in the cue alignment tests by replacing
the less important variables with "_".

Change-Id: Id8770b5f2045ad5c8ac6eee54d6a291d933a4b6f
2018-06-20 17:29:36 +00:00
Aaron Vaage 8d800446f3 Align Trick Play Tests With Other Media Tests
We have adopted some new standards for how we are writing the media
unit tests. This change goes through the trick play tests and
updates them to be more inline with how we are doing new media
tests.

This include using "_" for parameters that are not the focus of the
tests (used in the EXPECT calls).

This includes wrapping Dispatch calls so that the test bodies can
be more readable.

Change-Id: Iab4b1ce67666b6c8a4a821db1a8f4369cd366dc3
2018-06-19 19:48:18 +00:00
Aaron Vaage bf29257e48 Added IsVideoStreamInfo Test Matcher
Added a matcher for Video Streams. This will allow us to use a general
matcher in tests for video specific fields.

Change-Id: I91b9aebd66be37ec6d5f09b762263fafaef854c2
2018-06-19 19:48:10 +00:00