Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
SDK
/
exoplayer
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
a92e48e5
authored
Dec 07, 2021
by
bachinger
Committed by
Oliver Woodman
Dec 10, 2021
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Support IMA DAI streams for HLS
PiperOrigin-RevId: 414804513
parent
eaa4ab59
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
29 deletions
extensions/ima/src/main/java/com/google/android/exoplayer2/ext/ima/ImaUtil.java
library/common/src/main/java/com/google/android/exoplayer2/util/Util.java
library/core/src/main/java/com/google/android/exoplayer2/source/ads/ServerSideAdInsertionUtil.java
extensions/ima/src/main/java/com/google/android/exoplayer2/ext/ima/ImaUtil.java
View file @
a92e48e5
...
@@ -37,6 +37,7 @@ import com.google.ads.interactivemedia.v3.api.player.VideoAdPlayer;
...
@@ -37,6 +37,7 @@ import com.google.ads.interactivemedia.v3.api.player.VideoAdPlayer;
import
com.google.ads.interactivemedia.v3.api.player.VideoProgressUpdate
;
import
com.google.ads.interactivemedia.v3.api.player.VideoProgressUpdate
;
import
com.google.android.exoplayer2.C
;
import
com.google.android.exoplayer2.C
;
import
com.google.android.exoplayer2.ui.AdOverlayInfo
;
import
com.google.android.exoplayer2.ui.AdOverlayInfo
;
import
com.google.android.exoplayer2.ui.AdViewProvider
;
import
com.google.android.exoplayer2.upstream.DataSchemeDataSource
;
import
com.google.android.exoplayer2.upstream.DataSchemeDataSource
;
import
com.google.android.exoplayer2.upstream.DataSourceUtil
;
import
com.google.android.exoplayer2.upstream.DataSourceUtil
;
import
com.google.android.exoplayer2.upstream.DataSpec
;
import
com.google.android.exoplayer2.upstream.DataSpec
;
...
@@ -135,31 +136,28 @@ import java.util.Set;
...
@@ -135,31 +136,28 @@ import java.util.Set;
}
}
}
}
/** Stores configuration for
DAI ad playback
. */
/** Stores configuration for
playing server side ad insertion content
. */
static
final
class
Dai
Configuration
{
public
static
final
class
ServerSideAdInsertion
Configuration
{
public
final
AdErrorEvent
.
AdErrorListener
applicationAdErrorListener
;
public
final
AdViewProvider
adViewProvider
;
public
final
boolean
debugModeEnabled
;
public
final
ImaSdkSettings
imaSdkSettings
;
@Nullable
public
final
List
<
CompanionAdSlot
>
companionAdSlots
;
@Nullable
public
final
AdEvent
.
AdEventListener
applicationAdEventListener
;
@Nullable
public
final
AdEvent
.
AdEventListener
applicationAdEventListener
;
@Nullable
public
final
VideoAdPlayer
.
VideoAdPlayerCallback
applicationVideoAdPlayerCallback
;
@Nullable
public
final
AdErrorEvent
.
AdErrorListener
applicationAdErrorListener
;
@Nullable
public
final
ImaSdkSettings
imaSdkSettings
;
public
final
ImmutableList
<
CompanionAdSlot
>
companionAdSlots
;
public
final
boolean
debugModeEnabled
;
public
Dai
Configuration
(
public
ServerSideAdInsertion
Configuration
(
Ad
ErrorEvent
.
AdErrorListener
applicationAdErrorListen
er
,
Ad
ViewProvider
adViewProvid
er
,
@Nullable
List
<
CompanionAdSlot
>
companionAdSlot
s
,
ImaSdkSettings
imaSdkSetting
s
,
@Nullable
AdEvent
.
AdEventListener
applicationAdEventListener
,
@Nullable
AdEvent
.
AdEventListener
applicationAdEventListener
,
@Nullable
VideoAdPlayer
.
VideoAdPlayerCallback
applicationVideoAdPlayerCallback
,
@Nullable
AdErrorEvent
.
AdErrorListener
applicationAdErrorListener
,
@Nullable
ImaSdkSettings
imaSdkSetting
s
,
List
<
CompanionAdSlot
>
companionAdSlot
s
,
boolean
debugModeEnabled
)
{
boolean
debugModeEnabled
)
{
this
.
applicationAdErrorListener
=
applicationAdErrorListener
;
this
.
companionAdSlots
=
companionAdSlots
!=
null
?
ImmutableList
.
copyOf
(
companionAdSlots
)
:
null
;
this
.
applicationAdEventListener
=
applicationAdEventListener
;
this
.
applicationVideoAdPlayerCallback
=
applicationVideoAdPlayerCallback
;
this
.
imaSdkSettings
=
imaSdkSettings
;
this
.
imaSdkSettings
=
imaSdkSettings
;
this
.
adViewProvider
=
adViewProvider
;
this
.
applicationAdEventListener
=
applicationAdEventListener
;
this
.
applicationAdErrorListener
=
applicationAdErrorListener
;
this
.
companionAdSlots
=
ImmutableList
.
copyOf
(
companionAdSlots
);
this
.
debugModeEnabled
=
debugModeEnabled
;
this
.
debugModeEnabled
=
debugModeEnabled
;
}
}
}
}
...
...
library/common/src/main/java/com/google/android/exoplayer2/util/Util.java
View file @
a92e48e5
...
@@ -1142,6 +1142,18 @@ public final class Util {
...
@@ -1142,6 +1142,18 @@ public final class Util {
}
}
/**
/**
* Converts a time in seconds to the corresponding time in microseconds.
*
* @param timeSec The time in seconds.
* @return The corresponding time in microseconds.
*/
public
static
long
secToUs
(
double
timeSec
)
{
return
BigDecimal
.
valueOf
(
timeSec
)
.
multiply
(
BigDecimal
.
valueOf
(
C
.
MICROS_PER_SECOND
))
.
longValue
();
}
/**
* Parses an xs:duration attribute value, returning the parsed duration in milliseconds.
* Parses an xs:duration attribute value, returning the parsed duration in milliseconds.
*
*
* @param value The attribute value to decode.
* @param value The attribute value to decode.
...
...
library/core/src/main/java/com/google/android/exoplayer2/source/ads/ServerSideAdInsertionUtil.java
View file @
a92e48e5
...
@@ -67,16 +67,8 @@ public final class ServerSideAdInsertionUtil {
...
@@ -67,16 +67,8 @@ public final class ServerSideAdInsertionUtil {
.
withAdCount
(
insertionIndex
,
/* adCount= */
1
)
.
withAdCount
(
insertionIndex
,
/* adCount= */
1
)
.
withAdDurationsUs
(
insertionIndex
,
adDurationUs
)
.
withAdDurationsUs
(
insertionIndex
,
adDurationUs
)
.
withContentResumeOffsetUs
(
insertionIndex
,
contentResumeOffsetUs
);
.
withContentResumeOffsetUs
(
insertionIndex
,
contentResumeOffsetUs
);
long
followingAdGroupTimeUsOffset
=
-
adDurationUs
+
contentResumeOffsetUs
;
return
correctFollowingAdGroupTimes
(
for
(
int
i
=
insertionIndex
+
1
;
i
<
adPlaybackState
.
adGroupCount
;
i
++)
{
adPlaybackState
,
insertionIndex
,
adDurationUs
,
contentResumeOffsetUs
);
long
adGroupTimeUs
=
adPlaybackState
.
getAdGroup
(
i
).
timeUs
;
if
(
adGroupTimeUs
!=
C
.
TIME_END_OF_SOURCE
)
{
adPlaybackState
=
adPlaybackState
.
withAdGroupTimeUs
(
/* adGroupIndex= */
i
,
adGroupTimeUs
+
followingAdGroupTimeUsOffset
);
}
}
return
adPlaybackState
;
}
}
/**
/**
...
@@ -314,4 +306,21 @@ public final class ServerSideAdInsertionUtil {
...
@@ -314,4 +306,21 @@ public final class ServerSideAdInsertionUtil {
AdPlaybackState
.
AdGroup
adGroup
=
adPlaybackState
.
getAdGroup
(
adGroupIndex
);
AdPlaybackState
.
AdGroup
adGroup
=
adPlaybackState
.
getAdGroup
(
adGroupIndex
);
return
adGroup
.
count
==
C
.
LENGTH_UNSET
?
0
:
adGroup
.
count
;
return
adGroup
.
count
==
C
.
LENGTH_UNSET
?
0
:
adGroup
.
count
;
}
}
private
static
AdPlaybackState
correctFollowingAdGroupTimes
(
AdPlaybackState
adPlaybackState
,
int
adGroupInsertionIndex
,
long
insertedAdDurationUs
,
long
addedContentResumeOffsetUs
)
{
long
followingAdGroupTimeUsOffset
=
-
insertedAdDurationUs
+
addedContentResumeOffsetUs
;
for
(
int
i
=
adGroupInsertionIndex
+
1
;
i
<
adPlaybackState
.
adGroupCount
;
i
++)
{
long
adGroupTimeUs
=
adPlaybackState
.
getAdGroup
(
i
).
timeUs
;
if
(
adGroupTimeUs
!=
C
.
TIME_END_OF_SOURCE
)
{
adPlaybackState
=
adPlaybackState
.
withAdGroupTimeUs
(
/* adGroupIndex= */
i
,
adGroupTimeUs
+
followingAdGroupTimeUsOffset
);
}
}
return
adPlaybackState
;
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment