FileDocCategorySizeDatePackage
VideoDumpView.javaAPI DocAndroid 5.1 API26047Thu Mar 12 22:22:30 GMT 2015com.android.mediadump

VideoDumpView

public class VideoDumpView extends android.opengl.GLSurfaceView implements android.widget.MediaController.MediaPlayerControl
A view to play a video, specified by VideoDumpConfig.VIDEO_URI, and dump the screen into raw RGB files. It uses a renderer to display each video frame over a surface texture, read pixels, and writes the pixels into a rgb file on sdcard. Those raw rgb files will be used to compare the quality distortion against the original video. They can be viewed with the RgbPlayer app for debugging.

Fields Summary
private static final String
TAG
VideoDumpRenderer
mRenderer
private android.widget.MediaController
mMediaController
private boolean
mMediaControllerAttached
private android.media.MediaPlayer
mMediaPlayer
private BufferedWriter
mImageListWriter
Constructors Summary
public VideoDumpView(android.content.Context context)

    

       
        super(context);
        setEGLContextClientVersion(2);
        // GLSurfaceView uses RGB_5_6_5 by default.
        if (VideoDumpConfig.SET_CHOOSER) {
            setEGLConfigChooser(8, 8, 8, 8, 8, 8);
        }
        mRenderer = new VideoDumpRenderer(context);
        setRenderer(mRenderer);
    
Methods Summary
private voidattachMediaController()

        if (mMediaPlayer != null && mMediaController != null) {
            if (!mMediaControllerAttached) {
                mMediaController.setMediaPlayer(this);
                View anchorView = this.getParent() instanceof View ?
                        (View)this.getParent() : this;
                mMediaController.setAnchorView(anchorView);
                mMediaController.setEnabled(true);
                mMediaControllerAttached = true;
            }
            mMediaController.show();
        }
    
public booleancanPause()

        return true;
    
public booleancanSeekBackward()

        return true;
    
public booleancanSeekForward()

        return true;
    
public intgetAudioSessionId()

        return 0;
    
public intgetBufferPercentage()

        return 1;
    
public intgetCurrentPosition()

        if (isInPlaybackState()) {
            return mMediaPlayer.getCurrentPosition();
        }
        return 0;
    
public intgetDuration()

        return mMediaPlayer.getDuration();
    
private booleanisInPlaybackState()

        return (mMediaPlayer != null && mMediaPlayer.isPlaying());
    
public booleanisPlaying()

        return isInPlaybackState() && mMediaPlayer.isPlaying();
    
public voidonPause()

        stopPlayback();
        super.onPause();
    
public voidonResume()

        Log.d(TAG, "onResume");

        mMediaPlayer = new MediaPlayer();
        try {
            mMediaPlayer.setDataSource(VideoDumpConfig.VIDEO_URI);

            class RGBFilter implements FilenameFilter {
                public boolean accept(File dir, String name) {
                    return (name.endsWith(VideoDumpConfig.IMAGE_SUFFIX));
                }
            }
            File dump_dir = new File(VideoDumpConfig.ROOT_DIR);
            File[] dump_files = dump_dir.listFiles(new RGBFilter());
            for (File dump_file :dump_files) {
                dump_file.delete();
            }

            File image_list = new File(VideoDumpConfig.ROOT_DIR
                                       + VideoDumpConfig.IMAGES_LIST);
            image_list.delete();
            mImageListWriter = new BufferedWriter(new FileWriter(image_list));
        } catch (java.io.IOException e) {
            Log.e(TAG, e.getMessage(), e);
        }

        queueEvent(new Runnable(){
                public void run() {
                    mRenderer.setMediaPlayer(mMediaPlayer);
                    mRenderer.setImageListWriter(mImageListWriter);
                }});

        super.onResume();
    
public booleanonTouchEvent(android.view.MotionEvent ev)

        attachMediaController();
        return true;
    
public voidpause()

        mMediaPlayer.pause();
        try {
            mImageListWriter.flush();
        } catch (java.io.IOException e) {
            Log.e(TAG, e.getMessage(), e);
        }
    
public voidseekTo(int pos)

        mMediaPlayer.seekTo(pos);
    
public voidsetMediaController(android.widget.MediaController controller)

        if (mMediaController != null) {
            mMediaController.hide();
        }
        mMediaController = controller;
    
public voidstart()

        mMediaPlayer.start();
    
public voidstopPlayback()

        Log.d(TAG, "stopPlayback");

        if (mMediaPlayer != null) {
            mMediaPlayer.stop();
            mMediaPlayer.release();
            mMediaPlayer = null;
        }
        if (mImageListWriter != null) {
            try {
                mImageListWriter.flush();
                mImageListWriter.close();
            } catch (java.io.IOException e) {
                Log.e(TAG, e.getMessage(), e);
            }
        } else {
            Log.d(TAG, "image list file was not written successfully.");
        }