Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 190c03cb authored by Andreas Huber's avatar Andreas Huber
Browse files

Add the option '-S' to use surface allocated buffers in the stagefright cmdline tool.

Change-Id: Ic84eeed1679d6bf68c92de0e20d30e7a3c4d410f
parent d2e91d1d
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@ LOCAL_SRC_FILES:= \

LOCAL_SHARED_LIBRARIES := \
	libstagefright libmedia libutils libbinder libstagefright_foundation \
        libskia
        libskia libsurfaceflinger_client libgui

LOCAL_C_INCLUDES:= \
	$(JNI_H_INCLUDE) \
+61 −2
Original line number Diff line number Diff line
@@ -55,6 +55,11 @@

#include <fcntl.h>

#include <gui/SurfaceTextureClient.h>

#include <surfaceflinger/ISurfaceComposer.h>
#include <surfaceflinger/SurfaceComposerClient.h>

using namespace android;

static long gNumRepetitions;
@@ -66,6 +71,10 @@ static bool gWriteMP4;
static bool gDisplayHistogram;
static String8 gWriteMP4Filename;

static sp<ANativeWindow> gSurface;

#define USE_SURFACE_COMPOSER 0

static int64_t getNowUs() {
    struct timeval tv;
    gettimeofday(&tv, NULL);
@@ -138,7 +147,8 @@ static void playSource(OMXClient *client, sp<MediaSource> &source) {
        rawSource = OMXCodec::Create(
            client->interface(), meta, false /* createEncoder */, source,
            NULL /* matchComponentName */,
            gPreferSoftwareCodec ? OMXCodec::kPreferSoftwareCodecs : 0);
            gPreferSoftwareCodec ? OMXCodec::kPreferSoftwareCodecs : 0,
            gSurface);

        if (rawSource == NULL) {
            fprintf(stderr, "Failed to instantiate decoder for '%s'.\n", mime);
@@ -540,6 +550,7 @@ static void usage(const char *me) {
    fprintf(stderr, "       -k seek test\n");
    fprintf(stderr, "       -x display a histogram of decoding times/fps "
                    "(video only)\n");
    fprintf(stderr, "       -S allocate buffers from a surface\n");
}

int main(int argc, char **argv) {
@@ -550,6 +561,7 @@ int main(int argc, char **argv) {
    bool dumpProfiles = false;
    bool extractThumbnail = false;
    bool seekTest = false;
    bool useSurfaceAlloc = false;
    gNumRepetitions = 1;
    gMaxNumFrames = 0;
    gReproduceBug = -1;
@@ -563,7 +575,7 @@ int main(int argc, char **argv) {
    sp<LiveSession> liveSession;

    int res;
    while ((res = getopt(argc, argv, "han:lm:b:ptsow:kx")) >= 0) {
    while ((res = getopt(argc, argv, "han:lm:b:ptsow:kxS")) >= 0) {
        switch (res) {
            case 'a':
            {
@@ -642,6 +654,12 @@ int main(int argc, char **argv) {
                break;
            }

            case 'S':
            {
                useSurfaceAlloc = true;
                break;
            }

            case '?':
            case 'h':
            default:
@@ -780,6 +798,39 @@ int main(int argc, char **argv) {
        }
    }

    sp<SurfaceComposerClient> composerClient;
    sp<SurfaceControl> control;

    if (useSurfaceAlloc && !audioOnly) {
#if USE_SURFACE_COMPOSER
        composerClient = new SurfaceComposerClient;
        CHECK_EQ(composerClient->initCheck(), (status_t)OK);

        control = composerClient->createSurface(
                getpid(),
                String8("A Surface"),
                0,
                1280,
                800,
                PIXEL_FORMAT_RGB_565,
                0);

        CHECK(control != NULL);
        CHECK(control->isValid());

        CHECK_EQ(composerClient->openTransaction(), (status_t)OK);
        CHECK_EQ(control->setLayer(30000), (status_t)OK);
        CHECK_EQ(control->show(), (status_t)OK);
        CHECK_EQ(composerClient->closeTransaction(), (status_t)OK);

        gSurface = control->getSurface();
        CHECK(gSurface != NULL);
#else
        sp<SurfaceTexture> texture = new SurfaceTexture(0 /* tex */);
        gSurface = new SurfaceTextureClient(texture);
#endif
    }

    DataSource::RegisterDefaultSniffers();

    OMXClient client;
@@ -957,6 +1008,14 @@ int main(int argc, char **argv) {
        }
    }

    if (useSurfaceAlloc && !audioOnly) {
        gSurface.clear();

#if USE_SURFACE_COMPOSER
        composerClient->dispose();
#endif
    }

    client.disconnect();

    return 0;