use of org.chromium.base.CalledByNative in project chromeview by pwnall.
the class WebAudioMediaCodecBridge method decodeAudioFile.
@CalledByNative
private static boolean decodeAudioFile(Context ctx, int nativeMediaCodecBridge, int inputFD, long dataSize) {
if (dataSize < 0 || dataSize > 0x7fffffff)
return false;
MediaExtractor extractor = new MediaExtractor();
ParcelFileDescriptor encodedFD;
encodedFD = ParcelFileDescriptor.adoptFd(inputFD);
try {
extractor.setDataSource(encodedFD.getFileDescriptor(), 0, dataSize);
} catch (Exception e) {
e.printStackTrace();
encodedFD.detachFd();
return false;
}
if (extractor.getTrackCount() <= 0) {
encodedFD.detachFd();
return false;
}
MediaFormat format = extractor.getTrackFormat(0);
int channelCount = format.getInteger(MediaFormat.KEY_CHANNEL_COUNT);
int sampleRate = format.getInteger(MediaFormat.KEY_SAMPLE_RATE);
String mime = format.getString(MediaFormat.KEY_MIME);
long durationMicroseconds = 0;
if (format.containsKey(MediaFormat.KEY_DURATION)) {
try {
durationMicroseconds = format.getLong(MediaFormat.KEY_DURATION);
} catch (Exception e) {
Log.d(LOG_TAG, "Cannot get duration");
}
}
if (DEBUG) {
Log.d(LOG_TAG, "Tracks: " + extractor.getTrackCount() + " Rate: " + sampleRate + " Channels: " + channelCount + " Mime: " + mime + " Duration: " + durationMicroseconds + " microsec");
}
nativeInitializeDestination(nativeMediaCodecBridge, channelCount, sampleRate, durationMicroseconds);
// Create decoder
MediaCodec codec = MediaCodec.createDecoderByType(mime);
codec.configure(format, null, /* surface */
null, /* crypto */
0);
codec.start();
ByteBuffer[] codecInputBuffers = codec.getInputBuffers();
ByteBuffer[] codecOutputBuffers = codec.getOutputBuffers();
// A track must be selected and will be used to read samples.
extractor.selectTrack(0);
boolean sawInputEOS = false;
boolean sawOutputEOS = false;
// Keep processing until the output is done.
while (!sawOutputEOS) {
if (!sawInputEOS) {
// Input side
int inputBufIndex = codec.dequeueInputBuffer(TIMEOUT_MICROSECONDS);
if (inputBufIndex >= 0) {
ByteBuffer dstBuf = codecInputBuffers[inputBufIndex];
int sampleSize = extractor.readSampleData(dstBuf, 0);
long presentationTimeMicroSec = 0;
if (sampleSize < 0) {
sawInputEOS = true;
sampleSize = 0;
} else {
presentationTimeMicroSec = extractor.getSampleTime();
}
codec.queueInputBuffer(inputBufIndex, 0, /* offset */
sampleSize, presentationTimeMicroSec, sawInputEOS ? MediaCodec.BUFFER_FLAG_END_OF_STREAM : 0);
if (!sawInputEOS) {
extractor.advance();
}
}
}
// Output side
MediaCodec.BufferInfo info = new BufferInfo();
final int outputBufIndex = codec.dequeueOutputBuffer(info, TIMEOUT_MICROSECONDS);
if (outputBufIndex >= 0) {
ByteBuffer buf = codecOutputBuffers[outputBufIndex];
if (info.size > 0) {
nativeOnChunkDecoded(nativeMediaCodecBridge, buf, info.size);
}
buf.clear();
codec.releaseOutputBuffer(outputBufIndex, false);
if ((info.flags & MediaCodec.BUFFER_FLAG_END_OF_STREAM) != 0) {
sawOutputEOS = true;
}
} else if (outputBufIndex == MediaCodec.INFO_OUTPUT_BUFFERS_CHANGED) {
codecOutputBuffers = codec.getOutputBuffers();
}
}
encodedFD.detachFd();
codec.stop();
codec.release();
codec = null;
return true;
}
use of org.chromium.base.CalledByNative in project chromeview by pwnall.
the class BitmapHelper method decodeDrawableResource.
@CalledByNative
public static Bitmap decodeDrawableResource(String name) {
Resources res = Resources.getSystem();
int resource_id = res.getIdentifier(name, null, null);
return BitmapFactory.decodeResource(res, resource_id);
}
use of org.chromium.base.CalledByNative in project chromeview by pwnall.
the class MediaCodecBridge method configureAudio.
@CalledByNative
private void configureAudio(MediaFormat format, MediaCrypto crypto, int flags, boolean playAudio) {
mMediaCodec.configure(format, null, crypto, flags);
if (playAudio) {
int sampleRate = format.getInteger(MediaFormat.KEY_SAMPLE_RATE);
int channelCount = format.getInteger(MediaFormat.KEY_CHANNEL_COUNT);
int channelConfig = (channelCount == 1) ? AudioFormat.CHANNEL_OUT_MONO : AudioFormat.CHANNEL_OUT_STEREO;
int minBufferSize = AudioTrack.getMinBufferSize(sampleRate, channelConfig, AudioFormat.ENCODING_PCM_16BIT);
mAudioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, sampleRate, channelConfig, AudioFormat.ENCODING_PCM_16BIT, minBufferSize, AudioTrack.MODE_STREAM);
}
}
use of org.chromium.base.CalledByNative in project chromeview by pwnall.
the class MediaPlayerBridge method setDataSource.
@CalledByNative
private static boolean setDataSource(MediaPlayer player, Context context, String url, String cookies, boolean hideUrlLog) {
Uri uri = Uri.parse(url);
HashMap<String, String> headersMap = new HashMap<String, String>();
if (hideUrlLog)
headersMap.put("x-hide-urls-from-log", "true");
if (!TextUtils.isEmpty(cookies))
headersMap.put("Cookie", cookies);
try {
player.setDataSource(context, uri, headersMap);
return true;
} catch (Exception e) {
return false;
}
}
use of org.chromium.base.CalledByNative in project chromeview by pwnall.
the class MediaPlayerListener method create.
@CalledByNative
private static MediaPlayerListener create(int nativeMediaPlayerListener, Context context, MediaPlayer mediaPlayer) {
final MediaPlayerListener listener = new MediaPlayerListener(nativeMediaPlayerListener, context);
mediaPlayer.setOnBufferingUpdateListener(listener);
mediaPlayer.setOnCompletionListener(listener);
mediaPlayer.setOnErrorListener(listener);
mediaPlayer.setOnPreparedListener(listener);
mediaPlayer.setOnSeekCompleteListener(listener);
mediaPlayer.setOnVideoSizeChangedListener(listener);
if (PackageManager.PERMISSION_GRANTED == context.checkCallingOrSelfPermission(permission.WAKE_LOCK)) {
mediaPlayer.setWakeMode(context, android.os.PowerManager.FULL_WAKE_LOCK);
}
AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
am.requestAudioFocus(listener, AudioManager.STREAM_MUSIC, // Request permanent focus.
AudioManager.AUDIOFOCUS_GAIN);
return listener;
}
Aggregations