1

我是 Android 世界的新手,我必须在 Android 上编写一个流媒体视频质量检查器应用程序。我必须使用原生 StageFright 媒体框架来播放视频。据我了解,有一个渲染统计的本机 API,但我需要建议如何获得它。谢谢你。

4

2 回答 2

0

有一个 ADB 命令可以打印播放帧率。

程序

  1. 在主机上的 Windows(或 linux)上打开控制台。确保已安装所需的驱动程序,以便与设备(Android 手机或主板)进行 USB 连接

  2. 运行以下命令
    $> adb kill-server
    $> adb shell setprop debug.video.showfps 1

  3. 运行视频播放。如果视频正在使用 Android 媒体播放器堆栈运行,那么您将看到打印报告帧速率达到。

于 2011-07-20T13:46:21.613 回答
0

欢迎您也使用它,在渲染的每一帧的开头和结尾调用它。这是 NDK 中一些示例代码的略微修改版本:

stats.c:

#include <sys/time.h>
#include <string.h>
#include <android/log.h>
#include <stdio.h>
#include "stats.h"

#define  LOG_TAG    "[STATS]"
#define  LOGI(...)  __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
#define  LOGW(...)  __android_log_print(ANDROID_LOG_WARN,LOG_TAG,__VA_ARGS__)
#define  LOGE(...)  __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
#define  STATS_DUMP(...) __android_

double now_ms()
{
    struct timeval tv;
    gettimeofday(&tv, NULL);
    return tv.tv_sec*1000. + tv.tv_usec/1000.;
}

void stats_init(Stats* s)
{
    s->lastTime = now_ms();
    s->firstTime = 0.;
    s->firstFrame = 0;
    s->numFrames = 0;
    s->dump = malloc(128);
    memset(s->dump,0,128);
}

void stats_startFrame(Stats* s)
{
    s->frameTime = now_ms();
}

void stats_endFrame(Stats* s)
{
    double now = now_ms();
    double renderTime = now - s->frameTime;
    double frameTime  = now - s->lastTime;
    int nn;
    if (now - s->firstTime >= MAX_PERIOD_MS) {
        if (s->numFrames > 0) {
                double renderTime = now - s->frameTime;
                double frameTime  = now - s->lastTime;
                int nn;
                double minRender, maxRender, avgRender;
                double minFrame, maxFrame, avgFrame;
                int count;
                nn = s->firstFrame;
                minRender = maxRender = avgRender = s->frames[nn].renderTime;
                minFrame  = maxFrame  = avgFrame  = s->frames[nn].frameTime;
                for (count = s->numFrames; count > 0; count-- ) {
                    nn += 1;
                    if (nn >= MAX_FRAME_STATS)
                        nn -= MAX_FRAME_STATS;
                    double render = s->frames[nn].renderTime;
                    if (render < minRender) minRender = render;
                    if (render > maxRender) maxRender = render;
                    double frame = s->frames[nn].frameTime;
                    if (frame < minFrame) minFrame = frame;
                    if (frame > maxFrame) maxFrame = frame;
                    avgRender += render;
                    avgFrame  += frame;
                }
                avgRender /= s->numFrames;
                avgFrame  /= s->numFrames;
                sprintf(s->dump,"Frames per second - [AVG:%.1f] [MIN:%.1f] [MAX:%.1f]Rendering time ms - [AVG:%.1f] [MIN:%.1f] [MAX:%.1f]", 1000./avgFrame, 1000./maxFrame, 1000./minFrame, avgRender, minRender, maxRender);
                //LOGI("Frames per second - [AVG:%.1f] [MIN:%.1f] [MAX:%.1f]Rendering time ms - [AVG:%.1f] [MIN:%.1f] [MAX:%.1f]", 1000./avgFrame, 1000./maxFrame, 1000./minFrame, avgRender, minRender, maxRender);
        }
        s->numFrames  = 0;
        s->firstFrame = 0;
        s->firstTime  = now;
    }
    nn = s->firstFrame + s->numFrames;
    if (nn >= MAX_FRAME_STATS)
        nn -= MAX_FRAME_STATS;

    s->frames[nn].renderTime = renderTime;
    s->frames[nn].frameTime  = frameTime;

    if (s->numFrames < MAX_FRAME_STATS) {
        s->numFrames += 1;
    } else {
        s->firstFrame += 1;
        if (s->firstFrame >= MAX_FRAME_STATS)
            s->firstFrame -= MAX_FRAME_STATS;
    }

    s->lastTime = now;
}

stats.h:

#include <jni.h>
#define  MAX_FRAME_STATS  120
#define  MAX_PERIOD_MS    5000

typedef struct{
    double  renderTime;
    double  frameTime;
} FrameStats;

typedef struct{
    double  firstTime;
    double  lastTime;
    double  frameTime;
    int         firstFrame;
    int         numFrames;
    FrameStats  frames[ MAX_FRAME_STATS ];
    char* dump;
} Stats;

extern double now_ms();

extern void stats_init(Stats *);

extern int stats_dump(Stats *);

extern void stats_startFrame(Stats *);

extern void stats_endFrame(Stats *);
于 2012-11-27T19:49:13.490 回答