-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14256 from wordpress-mobile/try/using-lib-in-vide…
…o-compression-scenario Using stories lib in video compression scenario
- Loading branch information
Showing
13 changed files
with
449 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
WordPress/src/main/java/org/wordpress/android/ui/uploads/M4mVideoOptimizer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package org.wordpress.android.ui.uploads; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import org.m4m.MediaComposer; | ||
import org.wordpress.android.analytics.AnalyticsTracker; | ||
import org.wordpress.android.fluxc.model.MediaModel; | ||
import org.wordpress.android.ui.prefs.AppPrefs; | ||
import org.wordpress.android.util.AppLog; | ||
import org.wordpress.android.util.WPVideoUtils; | ||
import org.wordpress.android.util.analytics.AnalyticsUtils; | ||
|
||
import java.util.Map; | ||
|
||
import static org.wordpress.android.analytics.AnalyticsTracker.Stat.MEDIA_VIDEO_CANT_OPTIMIZE; | ||
|
||
public class M4mVideoOptimizer extends VideoOptimizerBase implements org.m4m.IProgressListener { | ||
public M4mVideoOptimizer( | ||
@NonNull MediaModel media, | ||
@NonNull VideoOptimizationListener listener) { | ||
super(media, listener); | ||
} | ||
|
||
/* | ||
* IProgressListener handlers | ||
*/ | ||
@Override | ||
public void onMediaStart() { | ||
mStartTimeMS = System.currentTimeMillis(); | ||
} | ||
|
||
@Override | ||
public void onMediaProgress(float progress) { | ||
sendProgressIfNeeded(progress); | ||
} | ||
|
||
@Override | ||
public void onMediaDone() { | ||
trackVideoProcessingEvents(false, null); | ||
selectMediaAndSendCompletionToListener(); | ||
} | ||
|
||
@Override | ||
public void onMediaPause() { | ||
AppLog.d(AppLog.T.MEDIA, "VideoOptimizer > paused"); | ||
} | ||
|
||
@Override | ||
public void onMediaStop() { | ||
// This seems to be called called in 2 cases. Do not use to check if we've manually stopped the composer. | ||
// 1. When the encoding is done without errors, before onMediaDone | ||
// 2. When we call 'stop' on the media composer | ||
AppLog.d(AppLog.T.MEDIA, "VideoOptimizer > stopped"); | ||
} | ||
|
||
@Override | ||
public void onError(Exception e) { | ||
AppLog.e(AppLog.T.MEDIA, "VideoOptimizer > Can't optimize the video", e); | ||
trackVideoProcessingEvents(true, e); | ||
mListener.onVideoOptimizationCompleted(mMedia); | ||
} | ||
|
||
@Override | ||
public void start() { | ||
if (!arePathsValidated()) return; | ||
|
||
MediaComposer mediaComposer = null; | ||
boolean wasNpeDetected = false; | ||
|
||
try { | ||
mediaComposer = WPVideoUtils.getVideoOptimizationComposer( | ||
getContext(), | ||
mInputPath, | ||
mOutputPath, | ||
this, | ||
AppPrefs.getVideoOptimizeWidth(), | ||
AppPrefs.getVideoOptimizeQuality()); | ||
} catch (NullPointerException npe) { | ||
AppLog.w( | ||
AppLog.T.MEDIA, | ||
"VideoOptimizer > NullPointerException while getting composer " + npe.getMessage() | ||
); | ||
wasNpeDetected = true; | ||
} | ||
|
||
if (mediaComposer == null) { | ||
AppLog.w(AppLog.T.MEDIA, "VideoOptimizer > null composer"); | ||
Map<String, Object> properties = AnalyticsUtils.getMediaProperties(getContext(), true, | ||
null, mInputPath); | ||
properties.put("was_npe_detected", wasNpeDetected); | ||
properties.put("optimizer-lib", "m4m"); | ||
AnalyticsTracker.track(MEDIA_VIDEO_CANT_OPTIMIZE, properties); | ||
mListener.onVideoOptimizationCompleted(mMedia); | ||
return; | ||
} | ||
|
||
// setup done. We're ready to optimize! | ||
try { | ||
mediaComposer.start(); | ||
AppLog.d(AppLog.T.MEDIA, "VideoOptimizer > composer started"); | ||
} catch (IllegalStateException e) { | ||
AppLog.e(AppLog.T.MEDIA, "VideoOptimizer > failed to start composer", e); | ||
mListener.onVideoOptimizationCompleted(mMedia); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
WordPress/src/main/java/org/wordpress/android/ui/uploads/Mp4ComposerVideoOptimizer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package org.wordpress.android.ui.uploads; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import com.daasuu.mp4compose.composer.ComposerInterface; | ||
import com.daasuu.mp4compose.composer.Listener; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.wordpress.android.analytics.AnalyticsTracker; | ||
import org.wordpress.android.fluxc.model.MediaModel; | ||
import org.wordpress.android.ui.prefs.AppPrefs; | ||
import org.wordpress.android.util.AppLog; | ||
import org.wordpress.android.util.WPVideoUtils; | ||
import org.wordpress.android.util.analytics.AnalyticsUtils; | ||
|
||
import java.util.Map; | ||
|
||
import static org.wordpress.android.analytics.AnalyticsTracker.Stat.MEDIA_VIDEO_CANT_OPTIMIZE; | ||
|
||
public class Mp4ComposerVideoOptimizer extends VideoOptimizerBase implements Listener { | ||
public Mp4ComposerVideoOptimizer( | ||
@NonNull MediaModel media, | ||
@NonNull VideoOptimizationListener listener) { | ||
super(media, listener); | ||
} | ||
|
||
@Override | ||
public void onStart() { | ||
mStartTimeMS = System.currentTimeMillis(); | ||
} | ||
|
||
@Override | ||
public void onProgress(double progress) { | ||
// this event fires quite often so we only call the listener when progress increases by 1% or more | ||
// NOTE: progress can be -1 with Mp4Composer library | ||
if (progress < 0) return; | ||
|
||
sendProgressIfNeeded((float) progress); | ||
} | ||
|
||
@Override | ||
public void onCompleted() { | ||
trackVideoProcessingEvents(false, null); | ||
selectMediaAndSendCompletionToListener(); | ||
} | ||
|
||
@Override | ||
public void onCanceled() { | ||
AppLog.d(AppLog.T.MEDIA, "VideoOptimizer > stopped"); | ||
} | ||
|
||
@Override | ||
public void onFailed(@NotNull Exception exception) { | ||
AppLog.e(AppLog.T.MEDIA, "VideoOptimizer > Can't optimize the video", exception); | ||
trackVideoProcessingEvents(true, exception); | ||
mListener.onVideoOptimizationCompleted(mMedia); | ||
} | ||
|
||
@Override public void start() { | ||
if (!arePathsValidated()) return; | ||
|
||
ComposerInterface composer = null; | ||
|
||
try { | ||
composer = WPVideoUtils.getVideoOptimizationComposer( | ||
mInputPath, | ||
mOutputPath, | ||
this, | ||
AppPrefs.getVideoOptimizeWidth(), | ||
AppPrefs.getVideoOptimizeQuality()); | ||
} catch (Exception e) { | ||
AppLog.w( | ||
AppLog.T.MEDIA, | ||
"VideoOptimizer > Exception while getting composer " + e.getMessage() | ||
); | ||
composer = null; | ||
} | ||
|
||
if (composer == null) { | ||
AppLog.w(AppLog.T.MEDIA, "VideoOptimizer > null composer"); | ||
Map<String, Object> properties = AnalyticsUtils.getMediaProperties(getContext(), true, | ||
null, mInputPath); | ||
properties.put("optimizer-lib", "mp4composer"); | ||
AnalyticsTracker.track(MEDIA_VIDEO_CANT_OPTIMIZE, properties); | ||
mListener.onVideoOptimizationCompleted(mMedia); | ||
return; | ||
} | ||
|
||
// setup done. We're ready to optimize! | ||
composer.start(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.