MediaRecorder 启动错误代码

MediaRecorder start error codes

我想录制没有声音的原始 h.264 视频,可能需要硬件加速(稍后再流式传输)。所以我决定使用 MediaRecorder(和套接字 hack 进行流式传输)。

我有以下代码:

final MediaRecorder recorder = new MediaRecorder();
final Camera camera = Camera.open();
camera.unlock();
recorder.setCamera(camera);
recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
recorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
final CamcorderProfile profile = CamcorderProfile.get(CamcorderProfile.QUALITY_LOW);
recorder.setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight);
recorder.setVideoFrameRate(profile.videoFrameRate);
recorder.setVideoEncodingBitRate(profile.videoBitRate);
recorder.prepare();
recorder.start();

砰!这在 logcat:

E/MediaRecorder﹕ start failed: -38

我开始谷歌搜索,发现了很多问题和答案,但是 none 关于我的错误代码 -38

所以我试着查看 Android source code,并注意到它是 native 方法,但我不知道在哪里可以找到它。

所以我的大问题是:是否有一些错误代码的列表,所以我可以找到错误 -38 的含义?`

也知道 tjat 我的目标是 API 10(姜饼)并使用最新的 SDK 21 构建。

好的,我想我有答案了。失败的启动函数在名为 mediarecorder.cpp 的文件中定义。在这里找到:

frameworks/av/media/libmedia/mediarecorder.cpp

此启动函数 returns 类型为 status_t 的变量,对应于您看到的抛出的错误。

现在,类型 status_t 在名为 Errors.h 的文件中定义,可以在此处找到:

system/core/include/utils/Errors.h

这定义了对应于 status_t 的枚举,如下所示:

enum {
    OK                = 0,    // Everything's swell.
    NO_ERROR          = 0,    // No errors.

    UNKNOWN_ERROR       = 0x80000000,

    NO_MEMORY           = -ENOMEM,
    INVALID_OPERATION   = -ENOSYS,
    BAD_VALUE           = -EINVAL,
    BAD_TYPE            = 0x80000001,
    NAME_NOT_FOUND      = -ENOENT,
    PERMISSION_DENIED   = -EPERM,
    NO_INIT             = -ENODEV,
    ALREADY_EXISTS      = -EEXIST,
    DEAD_OBJECT         = -EPIPE,
    FAILED_TRANSACTION  = 0x80000002,
    JPARKS_BROKE_IT     = -EPIPE,
#if !defined(HAVE_MS_C_RUNTIME)
    BAD_INDEX           = -EOVERFLOW,
    NOT_ENOUGH_DATA     = -ENODATA,
    WOULD_BLOCK         = -EWOULDBLOCK, 
    TIMED_OUT           = -ETIMEDOUT,
    UNKNOWN_TRANSACTION = -EBADMSG,
#else    
    BAD_INDEX           = -E2BIG,
    NOT_ENOUGH_DATA     = 0x80000003,
    WOULD_BLOCK         = 0x80000004,
    TIMED_OUT           = 0x80000005,
    UNKNOWN_TRANSACTION = 0x80000006,
#endif    
    FDS_NOT_ALLOWED     = 0x80000007,
};

如你所见,这里的一些值取自errno.h,所以我们只需要看看哪个值等于38。

根据this source,38对应ENOSYS。所以,如果我们回过头来看status_t枚举,我们可以看到在android中,ENOSYS对应的是一个无效的操作。不是很有帮助,但我希望这至少能为您指明正确的方向。

我在我的通话记录器应用程序中遇到了这个错误代码。 当您启动媒体记录器时,此错误代码将显示在 logcat 中,而 Microphone is in use 在另一个应用程序(如语音助手)中显示(例如:Ok google等)或其他通话记录器应用程序。