Use GL to render preview.

To speed up the preview, we direct the decoder output to a
SurfaceTexture, then draw the texture to a surface. The media
rendering parameters (crop, black-border) are implemented
using different vertex coordinates. The color effects are
implemented using fragment shaders. Currently only three color
effects are implemented, but that's all the appplication uses.

Change-Id: If84439fee572ed37ea077749ef9f2bd4f78703e1
diff --git a/libvideoeditor/lvpp/PreviewPlayerBase.cpp b/libvideoeditor/lvpp/PreviewPlayerBase.cpp
index e890423..3f75fb9 100644
--- a/libvideoeditor/lvpp/PreviewPlayerBase.cpp
+++ b/libvideoeditor/lvpp/PreviewPlayerBase.cpp
@@ -204,13 +204,6 @@
 
     mAudioStatusEventPending = false;
 
-    mYV12ColorConverter = new YV12ColorConverter();
-    if (!mYV12ColorConverter->isLoaded() ||
-        mYV12ColorConverter->getDecoderOutputFormat() == OMX_COLOR_FormatYUV420Planar) {
-        delete mYV12ColorConverter;
-        mYV12ColorConverter = NULL;
-    }
-
     reset();
 }
 
@@ -219,8 +212,6 @@
         mQueue.stop();
     }
 
-    delete mYV12ColorConverter;
-
     reset();
 
     mClient.disconnect();
@@ -1411,7 +1402,7 @@
                         : MediaSource::ReadOptions::SEEK_CLOSEST_SYNC);
         }
         for (;;) {
-            status_t err = readYV12Buffer(mVideoSource, &mVideoBuffer, &options);
+            status_t err = mVideoSource->read(&mVideoBuffer, &options);
             options.clearSeekTo();
 
             if (err != OK) {
@@ -1929,58 +1920,4 @@
     return OK;
 }
 
-status_t PreviewPlayerBase::readYV12Buffer(sp<MediaSource> source, MediaBuffer **buffer,
-    const MediaSource::ReadOptions *options) {
-    status_t result = source->read(buffer, options);
-    if (mYV12ColorConverter == NULL || *buffer == NULL) {
-        return result;
-    }
-
-    int width = mCropRect.right - mCropRect.left + 1;
-    int height = mCropRect.bottom - mCropRect.top + 1;
-
-    MediaBuffer *origBuffer = *buffer;
-    MediaBuffer *newBuffer = new MediaBuffer(width * height * 3 / 2);
-
-    LOGV("convertDecoderOutputToYV12: mGivenWidth = %d, mGivenHeight = %d",
-        mGivenWidth, mGivenHeight);
-    LOGV("width = %d, height = %d", width, height);
-
-    if (mYV12ColorConverter->convertDecoderOutputToYV12(
-        (uint8_t *)origBuffer->data(), // ?? + origBuffer->range_offset(), // decoderBits
-        mGivenWidth,  // decoderWidth
-        mGivenHeight,  // decoderHeight
-        mCropRect, // decoderRect
-        (uint8_t *)newBuffer->data() + newBuffer->range_offset() /* dstBits */) < 0) {
-        LOGE("convertDecoderOutputToYV12 failed");
-    }
-
-    // Copy the timestamp
-    int64_t timeUs;
-    CHECK(origBuffer->meta_data()->findInt64(kKeyTime, &timeUs));
-    newBuffer->meta_data()->setInt64(kKeyTime, timeUs);
-
-    origBuffer->release();
-    *buffer = newBuffer;
-
-    return result;
-}
-
-void PreviewPlayerBase::getVideoBufferSize(sp<MetaData> meta, int* width, int* height) {
-    if (mYV12ColorConverter) {
-        int32_t cropLeft, cropTop, cropRight, cropBottom;
-        if (meta->findRect(
-                kKeyCropRect, &cropLeft, &cropTop, &cropRight, &cropBottom)) {
-            *width = cropRight - cropLeft + 1;
-            *height = cropBottom - cropTop + 1;
-        } else {
-            CHECK(meta->findInt32(kKeyWidth, width));
-            CHECK(meta->findInt32(kKeyHeight, height));
-        }
-    } else {
-        CHECK(meta->findInt32(kKeyWidth, width));
-        CHECK(meta->findInt32(kKeyHeight, height));
-    }
-}
-
 }  // namespace android