-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
178 additions
and
47 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
91 changes: 91 additions & 0 deletions
91
lib/src/androidTest/java/com/otaliastudios/transcoder/integration/IssuesTests.kt
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,91 @@ | ||
package com.otaliastudios.transcoder.integration | ||
|
||
import android.media.MediaMetadataRetriever.METADATA_KEY_DURATION | ||
import android.media.MediaMetadataRetriever | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import androidx.test.platform.app.InstrumentationRegistry | ||
import com.otaliastudios.transcoder.Transcoder | ||
import com.otaliastudios.transcoder.TranscoderListener | ||
import com.otaliastudios.transcoder.TranscoderOptions | ||
import com.otaliastudios.transcoder.internal.utils.Logger | ||
import com.otaliastudios.transcoder.source.AssetFileDescriptorDataSource | ||
import com.otaliastudios.transcoder.source.ClipDataSource | ||
import com.otaliastudios.transcoder.source.FileDescriptorDataSource | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import java.io.File | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class IssuesTests { | ||
|
||
class Helper(val issue: Int) { | ||
|
||
val log = Logger("Issue$issue") | ||
val context = InstrumentationRegistry.getInstrumentation().context | ||
|
||
fun output( | ||
name: String = System.currentTimeMillis().toString(), | ||
extension: String = "mp4" | ||
) = File(context.cacheDir, "$name.$extension").also { it.parentFile!!.mkdirs() } | ||
|
||
fun input(filename: String) = AssetFileDescriptorDataSource( | ||
context.assets.openFd("issue_$issue/$filename") | ||
) | ||
|
||
fun transcode( | ||
output: File = output(), | ||
assertTranscoded: Boolean = true, | ||
assertDuration: Boolean = true, | ||
builder: TranscoderOptions.Builder.() -> Unit, | ||
): File { | ||
val transcoder = Transcoder.into(output.absolutePath) | ||
transcoder.apply(builder) | ||
transcoder.setListener(object : TranscoderListener { | ||
override fun onTranscodeCanceled() = Unit | ||
override fun onTranscodeCompleted(successCode: Int) { | ||
if (assertTranscoded) { | ||
require(successCode == Transcoder.SUCCESS_TRANSCODED) | ||
} | ||
} | ||
override fun onTranscodeFailed(exception: Throwable) = Unit | ||
override fun onTranscodeProgress(progress: Double) = Unit | ||
}) | ||
transcoder.transcode().get() | ||
if (assertDuration) { | ||
val retriever = MediaMetadataRetriever() | ||
retriever.setDataSource(output.absolutePath) | ||
val duration = retriever.extractMetadata(METADATA_KEY_DURATION)!!.toLong() | ||
log.e("Video duration is $duration") | ||
assert(duration > 0L) | ||
retriever.release() | ||
} | ||
return output | ||
} | ||
} | ||
|
||
|
||
@Test | ||
fun issue137() = with(Helper(137)) { | ||
transcode { | ||
addDataSource(ClipDataSource(input("main.mp3"), 0L, 1000_000L)) | ||
addDataSource(input("0.amr")) | ||
addDataSource(ClipDataSource(input("main.mp3"), 0L, 1000_000L)) | ||
addDataSource(input("1.amr")) | ||
addDataSource(ClipDataSource(input("main.mp3"), 0L, 1000_000L)) | ||
addDataSource(input("2.amr")) | ||
addDataSource(ClipDataSource(input("main.mp3"), 0L, 1000_000L)) | ||
addDataSource(input("3.amr")) | ||
addDataSource(ClipDataSource(input("main.mp3"), 0L, 1000_000L)) | ||
addDataSource(input("4.amr")) | ||
addDataSource(ClipDataSource(input("main.mp3"), 0L, 1000_000L)) | ||
addDataSource(input("5.amr")) | ||
addDataSource(ClipDataSource(input("main.mp3"), 0L, 1000_000L)) | ||
addDataSource(input("6.amr")) | ||
addDataSource(ClipDataSource(input("main.mp3"), 0L, 1000_000L)) | ||
addDataSource(input("7.amr")) | ||
addDataSource(ClipDataSource(input("main.mp3"), 0L, 1000_000L)) | ||
addDataSource(input("8.amr")) | ||
} | ||
Unit | ||
} | ||
} |
4 changes: 1 addition & 3 deletions
4
...e/internal/ISO6709LocationParserTest.java → ...rnal/utils/ISO6709LocationParserTest.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
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
22 changes: 22 additions & 0 deletions
22
lib/src/main/java/com/otaliastudios/transcoder/source/AssetFileDescriptorDataSource.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,22 @@ | ||
package com.otaliastudios.transcoder.source; | ||
|
||
import android.content.res.AssetFileDescriptor; | ||
import android.media.MediaExtractor; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
|
||
/** | ||
* It is the caller responsibility to close the file descriptor. | ||
*/ | ||
public class AssetFileDescriptorDataSource extends DataSourceWrapper { | ||
public AssetFileDescriptorDataSource(@NonNull AssetFileDescriptor assetFileDescriptor) { | ||
super(new FileDescriptorDataSource( | ||
assetFileDescriptor.getFileDescriptor(), | ||
assetFileDescriptor.getStartOffset(), | ||
assetFileDescriptor.getDeclaredLength() | ||
)); | ||
} | ||
} |
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
Oops, something went wrong.