Search in sources :

Example 11 with CalledByNative

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;
}
Also used : MediaFormat(android.media.MediaFormat) BufferInfo(android.media.MediaCodec.BufferInfo) MediaExtractor(android.media.MediaExtractor) ByteBuffer(java.nio.ByteBuffer) BufferInfo(android.media.MediaCodec.BufferInfo) MediaCodec(android.media.MediaCodec) ParcelFileDescriptor(android.os.ParcelFileDescriptor) CalledByNative(org.chromium.base.CalledByNative)

Example 12 with CalledByNative

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);
}
Also used : Resources(android.content.res.Resources) CalledByNative(org.chromium.base.CalledByNative)

Example 13 with CalledByNative

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);
    }
}
Also used : AudioTrack(android.media.AudioTrack) CalledByNative(org.chromium.base.CalledByNative)

Example 14 with CalledByNative

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;
    }
}
Also used : HashMap(java.util.HashMap) Uri(android.net.Uri) InvocationTargetException(java.lang.reflect.InvocationTargetException) CalledByNative(org.chromium.base.CalledByNative)

Example 15 with CalledByNative

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;
}
Also used : AudioManager(android.media.AudioManager) CalledByNative(org.chromium.base.CalledByNative)

Aggregations

CalledByNative (org.chromium.base.CalledByNative)24 Intent (android.content.Intent)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 PackageManager (android.content.pm.PackageManager)3 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)3 ActivityNotFoundException (android.content.ActivityNotFoundException)2 PackageInfo (android.content.pm.PackageInfo)2 SurfaceTexture (android.graphics.SurfaceTexture)2 Uri (android.net.Uri)2 Method (java.lang.reflect.Method)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 RSAPrivateKey (java.security.interfaces.RSAPrivateKey)2 HashMap (java.util.HashMap)2 BroadcastReceiver (android.content.BroadcastReceiver)1 Context (android.content.Context)1 IntentFilter (android.content.IntentFilter)1 ApplicationInfo (android.content.pm.ApplicationInfo)1 Resources (android.content.res.Resources)1 Canvas (android.graphics.Canvas)1 Picture (android.graphics.Picture)1