4870 Commits

Author SHA1 Message Date
claincly
44f461a062 Make sure first frame has effects applied.
`FrameProcessorManager` now reports it's not ready when the output surface is set but not the output resolution. `FrameProcessorManager` allows playback without an output surface, like with ExoPlayer.

PiperOrigin-RevId: 504626088
2023-02-01 13:21:03 +00:00
samrobinson
fcc994b825 Rename FloatResamplingAudioProcessor to ToFloatPcmAudioProcessor.
Resampling as a term is overloaded, however it was raised as a
confusing term in a meeting recently, as the 1P team initially thought
this would change the sample rate. The naming of this `AudioProcessor`
now matches `ToInt16PcmAudioProcessor`.

PiperOrigin-RevId: 503441019
2023-01-23 13:48:05 +00:00
kimvde
a4f9f9487b Add the possility to shift frame timestamps in SampleConsumer
This is needed for constrained multi-asset to shift the timestamps of
the media items that are not the first in the sequence.

PiperOrigin-RevId: 502409923
2023-01-17 03:30:32 +00:00
samrobinson
eb49666049 Move SonicAudioProcessor to media3.common module.
PiperOrigin-RevId: 501881646
2023-01-17 03:10:32 +00:00
claincly
07fe60710c Fix not able to set a null output surface.
Previously, after calling MCVR.setOutput() with null, `frameProcessorManager`'s output surface is cleared. What was unexpected is `ExoPlayerInternal` notifies a zero output resolution after clearing the output surface. This zero resolution causes FrameProcessor to fail.

PiperOrigin-RevId: 501861993
2023-01-17 02:58:45 +00:00
claincly
91d43dc915 Handle FrameProcessor output size change
Notifies event listener of FrameProcessor's new output size to layout the
PlayerView

PiperOrigin-RevId: 501590239
2023-01-17 02:43:03 +00:00
samrobinson
298ad765a3 Make ToInt16AudioProcessor available in common.audio.
PiperOrigin-RevId: 501575932
2023-01-17 02:35:14 +00:00
samrobinson
8ccb8b64ae Move BaseAudioProcessor abstract class to common.
This is a prerequisite step to making the `ResamplingAudioProcessor` public.

PiperOrigin-RevId: 501545561
2023-01-17 02:27:27 +00:00
bachinger
055ed77433 Document that DownloadService needs notification permissions
Starting with Android 13 (API 33) an app needs to request the
permission to post notifications or notifications are suppressed.
This change documents this in the class level JavaDoc of the
`DownloadService`.

Issue: google/ExoPlayer#10884
PiperOrigin-RevId: 501346908
2023-01-17 02:19:33 +00:00
claincly
74cc588049 Fix typo in ExoPlayer.java
PiperOrigin-RevId: 501287961
2023-01-17 02:07:28 +00:00
tonihei
09a15fb731 Update bandwidth meter estimates
PiperOrigin-RevId: 501010994
2023-01-10 20:55:15 +00:00
tonihei
3c6b8c5d7b Handle AV sync timestamps when draining the audio sink during tunneling
When audio processors are enabled during tunneling, they must produce
output immediately, ensuring that the timestamps of the output samples
correspond to the input and that no additional samples are produced.
This requirement is documented in the Javadoc of DefaultAudioSink.

However, this alone doesn't guarantee all buffers are immediately
written to the AudioTrack, because the AudioTrack writes are
non-blocking and may need multiple attempts.

When draining the audio sink at the end of the stream, we currently
fail in this situation because we assert that the timestamp must be
set (=the drain operation is a no-op). But this may not be true when
the previous non-blocking write wasn't fully handled. We can fix this
by saving the last timestamp and reusing it during draining.

Issue: google/ExoPlayer#10847
PiperOrigin-RevId: 500943891
2023-01-10 20:51:19 +00:00
rohks
d49437c6e1 Initialise fields used for bundling as String directly
Initialising the fields as Integer and then getting a String on compute time is slow. Instead we directly initialise these fields as String. Improves the time taken in bundling PlayerInfo further to less than 200ms from ~300ms.

Also modified a test to improve productive coverage.

PiperOrigin-RevId: 500003935
2023-01-10 20:20:08 +00:00
rohks
bdd6818c14 Fix typo in DefaultTrackSelector.Parameters field
PiperOrigin-RevId: 499905136
2023-01-10 20:16:03 +00:00
andrewlewis
9835e91439 Fix some minor issues/typos
PiperOrigin-RevId: 499808853
2023-01-10 20:08:14 +00:00
claincly
a4bc0959be Support previewing HDR on API33+
FrameProcessor already support using different transfer function for input and
output color. This CL has two major changes:

- Create an eglSurface that recognizes BT.2020 PQ
  - This requires a separate extension that works only after 33
  - So we current throw, if input is HDR, and this extension doesn't work
- Create FrameProcessor with PQ output transfer function

PiperOrigin-RevId: 496023758
2022-12-21 16:28:37 +00:00
tonihei
5e23b8bfd5 Check if codec still exists before handling tunneling events
The tunneling callbacks are sent via Handler messages and may be
handled after the codec/surface was changed or released.

We already guard against the codec/surface change condition by
creating a new listener and verifying that the current callback
happens for the correct listener instance, but we don't guard
against a released codec yet.

PiperOrigin-RevId: 495882353
2022-12-21 16:24:44 +00:00
tonihei
a1c0b10482 Clarify behavior for out-of-bounds indices and align implementations
Some Player methods operate relative to existing indices in the
playlist (add,remove,move,seek). As these operations may be issued
from a place with a stale playlist (e.g. a controller that sends
a command while the playlist is changing), we have to handle out-
of-bounds indices gracefully. In most cases this is already
documented and implemented correctly. However, some cases are not
documented and the existing player implementations don't handle
these cases consistently (or in some cases not even correctly).

PiperOrigin-RevId: 495856295
2022-12-21 16:16:54 +00:00
rohks
74559b4a18 Rename EMPTY_MEDIA_ITEM to PLACEHOLDER_MEDIA_ITEM
The `MediaItem` instances in the following cases are not actually empty but acts as a placeholder. `EMPTY_MEDIA_ITEM` can also be confused with `MediaItem.EMPTY`.

PiperOrigin-RevId: 495843012
2022-12-21 16:09:14 +00:00
claincly
c9e644b4f7 Allow changing output surface in previewing
It covers the following cases:

| From/To     | `null` | `surface 0` | `surface 1` |
|-------------|--------|-------------|-------------|
| `null`      | 🆖      | 📺           | 📺           |
| `surface 0` |       | 🔁           | 📺           |
| `surface 1` |       | 📺           | 🔁           |

Where
- 🆖 means NOP
-  means
  - Set `null` on FrameProcessor, effectively dropping all frames
- 📺 means
  - Notify the listener of video size
  - Set FrameProcessor output surface and size when MSG_SET_VIDEO_OUTPUT_SIZE is received
- 🔁 means
  - Notify the listener of video size

PiperOrigin-RevId: 495477620
2022-12-15 17:11:56 +00:00
claincly
d5ae76870e Apply frame release time adjustment in preview mode
PiperOrigin-RevId: 495471548
2022-12-15 17:07:59 +00:00
claincly
678b29c10d Make Codec release frames to frame processor.
PiperOrigin-RevId: 495406734
2022-12-15 17:03:52 +00:00
claincly
4398af3a4d Create frame processor in MCVR
PiperOrigin-RevId: 495368262
2022-12-15 16:55:45 +00:00
claincly
d77ceaacc4 Use Size in MSG_SET_VIDEO_OUTPUT_RESOLUTION.
PiperOrigin-RevId: 495055151
2022-12-15 16:24:39 +00:00
tonihei
6e0f1f10b3 Forward seek command details to seekTo method in BasePlayer
BasePlayer simplifies implementations by handling all the various
seek methods and forwarding to a single method that can then be
implemented by subclasses. However, this loses the information about
the concrete entry point used for seeking, which is relevant when
the subclass wants to verify or filter by Player.Command. This
can be improved by adding the command as a new parameter. Since
we have to change the method anyway, we can also incorporate the
boolean flag about whether the current item is repeated to avoid
the separate method.

PiperOrigin-RevId: 494948094
2022-12-15 16:04:59 +00:00
samrobinson
26d75baaeb Add handling for null input buffer in DefaultAudioSink processBuffers.
#minor-release

PiperOrigin-RevId: 494166943
2022-12-12 14:48:58 +00:00
claincly
92bd4c6137 Clarify the size notification logic in MCVR
- Use a single `VideoSize` instance instead of four primitive fields.
- Clarify that the reported size is the decoded size, that is the encoded video
  size.

PiperOrigin-RevId: 494148190
2022-12-12 14:44:44 +00:00
tonihei
e9364b0f6e Clarify and correct allowed multi-threading for some Player methods
Some Player methods like getting the Looper and adding listeners
were always allowed to be called from any thread, but this is
undocumented. This change makes the threading rules of these
methods more explicit.

Removing listeners was never meant to be called from another thread
and we also don't support it safely because final callbacks may
be triggered from the wrong thread. To find potential issues, we
can assert the correct thread when releasing listeners.

Finally, there is a potential race condition when calling addListener
from a different thread at the same time as release, which may lead to
a registered listener that could receive callbacks after the player is
released.

PiperOrigin-RevId: 493843981
2022-12-12 14:23:55 +00:00
claincly
e6bf908b5a Add render messages for setting video output resolution
An AndroidTest is needed to test the message sending from ExoPlayerImpl to
a video renderer (MCVR in this case). The test will be added later.

PiperOrigin-RevId: 493602259
2022-12-12 14:11:15 +00:00
claincly
03276d1eb0 Rename surface to display surface for previewing.
PiperOrigin-RevId: 493557119
2022-12-12 14:07:01 +00:00
ibaker
d6c872494b Deprecate C.POSITION_UNSET in favour of C.INDEX_UNSET
These have the same value (`-1`), and basically the same meaning (offset
in an array/list/file/byte stream/etc), but 'position' is an overloaded
term in a media playback library, and there's a risk people assume that
methods like `Player.getCurrentPosition()` may return
`C.POSITION_UNSET`, when in fact unset media times (whether duration or
position) are always represented by `C.TIME_UNSET` which is a) a `long`
(not `int`) and b) a different underlying value. (aside:
`getCurrentPosition()` never returns an unset value, but it's a good
example of the ambiguity of the word 'position' between 'byte offset'
and 'media timestamp'.)

PiperOrigin-RevId: 492493102
2022-12-12 12:24:50 +00:00
ibaker
2f8cf947c7 Fix ExoPlayerTest to use C.TIME_UNSET instead of C.POSITION_UNSET
This inconsistency was exposed by an upcoming change to deprecate
`POSITION_UNSET` in favour of `INDEX_UNSET` because position is an
ambiguous term between 'byte offset' and 'media position', as shown
here.

PiperOrigin-RevId: 492470241
2022-12-12 12:16:29 +00:00
ibaker
5f6fde4d2a Fix TextRenderer exception when a subtitle file contains no cues
Discovered while investigating Issue: google/ExoPlayer#10823

Example stack trace with the previous code (I added the index value for
debugging):

```
playerFailed [eventTime=44.07, mediaPos=44.01, window=0, period=0, errorCode=ERROR_CODE_FAILED_RUNTIME_CHECK
  androidx.media3.exoplayer.ExoPlaybackException: Unexpected runtime error
      at androidx.media3.exoplayer.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:635)
      at android.os.Handler.dispatchMessage(Handler.java:102)
      at android.os.Looper.loopOnce(Looper.java:202)
      at android.os.Looper.loop(Looper.java:291)
      at android.os.HandlerThread.run(HandlerThread.java:67)
  Caused by: java.lang.IllegalArgumentException: index=-1
      at androidx.media3.common.util.Assertions.checkArgument(Assertions.java:55)
      at androidx.media3.extractor.text.webvtt.WebvttSubtitle.getEventTime(WebvttSubtitle.java:62)
      at androidx.media3.extractor.text.SubtitleOutputBuffer.getEventTime(SubtitleOutputBuffer.java:56)
      at androidx.media3.exoplayer.text.TextRenderer.getCurrentEventTimeUs(TextRenderer.java:435)
      at androidx.media3.exoplayer.text.TextRenderer.render(TextRenderer.java:268)
      at androidx.media3.exoplayer.ExoPlayerImplInternal.doSomeWork(ExoPlayerImplInternal.java:1008)
      at androidx.media3.exoplayer.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:509)
      at android.os.Handler.dispatchMessage(Handler.java:102)
      at android.os.Looper.loopOnce(Looper.java:202)
      at android.os.Looper.loop(Looper.java:291)
      at android.os.HandlerThread.run(HandlerThread.java:67)
]
```

#minor-release

PiperOrigin-RevId: 492464180
2022-12-12 12:12:08 +00:00
christosts
e219ac21ae Use audio bitrate to calculate AudioTrack min buffer in passthrough
Use the bitrate of the audio format (when available) in
DefaultAudioSink.AudioTrackBufferSizeProvider.getBufferSizeInBytes() to
calculate accurate buffer sizes for direct (passthrough) playbacks.

#minor-release

PiperOrigin-RevId: 491628530
2022-11-29 19:49:50 +00:00
tonihei
4cf877b814 Add configuration to support OPUS offload
To support OPUS offload, we need to provide a few configuration values
that are currently not set due to the lack of devices supporting
OPUS offload.

PiperOrigin-RevId: 491613716
2022-11-29 19:42:25 +00:00
Rohit Singh
3a7f940f41 Merge pull request #10776 from dongvanhung:feature/add_support_clear_download_manager_helpers
PiperOrigin-RevId: 491336828
2022-11-29 19:23:32 +00:00
Rohit Singh
c827e46c3d Merge pull request #10799 from OxygenCobalt:id3v2-multi-value
PiperOrigin-RevId: 491289028
2022-11-29 19:04:05 +00:00
tonihei
7d62943bcd Remove flakiness from DefaultAnalyticsCollectorTest
Our FakeClock generally makes sure that playback tests are fully
deterministic. However, this fails if the test uses blocking waits
with clock.onThreadBlocked and where relevant Handlers are created
without using the clock.

To fix the flakiness, we can make the following adjustments:
 - Use TestExoPlayerBuilder instead of legacy ExoPlayerTestRunner
   to avoid onThreadBlocked calls. This also makes the tests more
   readable.
 - Use clock to create Handler for FakeVideoRenderer and
   FakeAudioRenderer. Ideally, this should be passed through
   RenderersFactory, but it's too disruptive given this is a
   public API.
 - Use clock for MediaSourceList and MediaPeriodQueue update
   handler.

PiperOrigin-RevId: 490907495
2022-11-29 18:47:59 +00:00
Alexander Capehart
46f376e40b
Fix non-updated constructor usage
Fix a constructor usage that tried to use an array instead of a list.
2022-11-21 14:01:01 -07:00
Alexander Capehart
0eb56f65b0
Improve multi-value text frame parsing
Rework the parsing of multi-value text frames to reduce duplication
and increase efficiency.
2022-11-21 11:55:14 -07:00
christosts
d9d716869b Pass correct frame size for passthrough playback
When estimating the AudioTrack min buffer size, we must use a PCM
frame of 1 when doing direct playback (passthrough). The code was
passing -1 (C.LENGTH_UNSET).

PiperOrigin-RevId: 489238392
2022-11-21 15:29:59 +00:00
tonihei
cbcdbfe021 Add additional codecs to the eosPropagationWorkaround list.
Issue: google/ExoPlayer#10756
PiperOrigin-RevId: 489236336
2022-11-21 15:24:23 +00:00
ibaker
058cba95d4 Remove @hide javadoc annotation from ExoPlayer GitHub
This tag is only understood by Dackka, which is used to generate the media3 javadoc.

PiperOrigin-RevId: 489233200
2022-11-21 15:12:52 +00:00
Googler
79b809b556 Add setPlaybackLooper ExoPlayer builder method
The method allows clients to specify a pre-existing thread
to use for playback. This can be used to run multiple ExoPlayer
instances on the same playback thread.

PiperOrigin-RevId: 488980749
2022-11-21 14:35:11 +00:00
Googler
f52bb274b8 Fix NPE when listener is not set
PiperOrigin-RevId: 488970696
2022-11-21 14:31:26 +00:00
kimvde
ea7e8cff3a Refactor transformation completion
PiperOrigin-RevId: 488929446
2022-11-21 14:27:00 +00:00
Alexander Capehart
4510210ad7
Merge branch 'multi-value-id3v2' into dev-v2 2022-11-20 18:05:45 -07:00
Alexander Capehart
d8729e552c
Fix second-order issues
Fix second-order issues stemming from the addition of multi-value tags.
2022-11-20 18:02:45 -07:00
tonihei
8438daca1f Rename getVideoSurfaceSize to getSurfaceSize
This better matches the callback name (onSurfaceSizeChanged) and
probably cause less confusion with getVideoSize.

PiperOrigin-RevId: 488669786
2022-11-16 12:32:35 +00:00
christosts
1b24e6fd14 Set valid channel masks for 8 and 12 channels on all Android versions
Util.getAudioTrackChannelConfig() maps a channel count to a
channel mask that is passed to AudioTrack. The method expected that
playback of 8-channel audio is possible from Android 5.1 and playback of
12-channel audio is only possible from Android 12L. However, there is no
restriction on the upper number of channels that can be passed to the
AudioTrack. google/ExoPlayer#10701 is an example where the audio decoder
outputs 12 channels on an Android 10.

This change removes the restrictions for 8 and 12 channels. Note, we still
do not support playback of arbitrary number of channels as it would require
further changes to DefaultAudioSink.

#minor-release

Issue: google/ExoPlayer#10701
PiperOrigin-RevId: 488659831
2022-11-16 12:28:48 +00:00