예제 #1
0
long CoreAudioEncoder::inputDataProc(UInt32 *npackets, AudioBufferList *abl)
{
    prepareInputBuffer(abl, *npackets);
    AudioBuffer &ab = abl->mBuffers[0];
    try {
        *npackets = readSamples(ab.mData, *npackets);
    } catch (...) {
        /* treat as EOF */
        *npackets = 0;
    }
    ab.mDataByteSize = *npackets * m_input_desc.mBytesPerFrame;
    if (*npackets == 0)
        ab.mData = 0;
    return 0;
}
예제 #2
0
bool EncodeInputSurface::init(const char* inputFileName, uint32_t fourcc, int width, int height)
{
    m_width = width;
    m_height = height;

    int surfaceWidth = width;
    int surfaceHeight = height;
    static sp<SurfaceComposerClient> client = new SurfaceComposerClient();
    //create surface
    static sp<SurfaceControl> surfaceCtl = client->createSurface(String8("testsurface"),
        surfaceWidth, surfaceHeight, HAL_PIXEL_FORMAT_NV12_Y_TILED_INTEL, 0);
    DEBUG("create surface with size %dx%d, format: 0x%x", surfaceWidth, surfaceHeight, HAL_PIXEL_FORMAT_NV12_Y_TILED_INTEL);

    // configure surface
    SurfaceComposerClient::openGlobalTransaction();
    surfaceCtl->setLayer(100000);
    surfaceCtl->setPosition(100, 100);
    surfaceCtl->setSize(surfaceWidth, surfaceHeight);
    SurfaceComposerClient::closeGlobalTransaction();

    m_surface = surfaceCtl->getSurface();
    mNativeWindow = m_surface;

    int bufWidth = width;
    int bufHeight = height;
    int ret;

    INFO("set buffers geometry %dx%d\n", width, height);
    ret = native_window_set_buffers_dimensions(GET_ANATIVEWINDOW(mNativeWindow), width, height);
    CHECK_RET(ret, "native_window_set_buffers_dimensions");

    uint32_t format = HAL_PIXEL_FORMAT_NV12_Y_TILED_INTEL;
    INFO("set buffers format %x\n", format);
    ret = native_window_set_buffers_format(GET_ANATIVEWINDOW(mNativeWindow), format);
    CHECK_RET(ret, "native_window_set_buffers_format");

    INFO("set buffer usage\n");
    ret = native_window_set_usage(GET_ANATIVEWINDOW(mNativeWindow),
        GRALLOC_USAGE_HW_VIDEO_ENCODER | GRALLOC_USAGE_HW_TEXTURE);
    CHECK_RET(ret, "native_window_set_usage");

    INFO("set buffer count %d\n", m_bufferCount);
    ret = native_window_set_buffer_count(GET_ANATIVEWINDOW(mNativeWindow), m_bufferCount);
    CHECK_RET(ret, "native_window_set_buffer_count");

    prepareInputBuffer();
    return true;
}
예제 #3
0
long CoreAudioEncoder::inputDataProc(UInt32 *npackets, AudioBufferList *abl)
{
    prepareInputBuffer(abl, *npackets);
    AudioBuffer &ab = abl->mBuffers[0];
    try {
#if defined(_MSC_VER) && defined(_DEBUG)
	_CrtCheckMemory();
#endif
	*npackets = m_src->readSamples(ab.mData, *npackets);
#if defined(_MSC_VER) && defined(_DEBUG)
	_CrtCheckMemory();
#endif
    } catch (...) {
	return -39; // eofError
    }
    if (*npackets == 0) {
	ab.mData = 0;
	ab.mDataByteSize = 0;
    } else
	ab.mDataByteSize = *npackets * m_input_desc.mBytesPerFrame;
    m_stat.updateRead(*npackets);
    return 0;
}