本文整理汇总了C++中sp::addTrack方法的典型用法代码示例。如果您正苦于以下问题:C++ sp::addTrack方法的具体用法?C++ sp::addTrack怎么用?C++ sp::addTrack使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sp
的用法示例。
在下文中一共展示了sp::addTrack方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: runEncoder
/*
* Runs the MediaCodec encoder, sending the output to the MediaMuxer. The
* input frames are coming from the virtual display as fast as SurfaceFlinger
* wants to send them.
*
* The muxer must *not* have been started before calling.
*/
static status_t runEncoder(const sp<MediaCodec>& encoder,
const sp<MediaMuxer>& muxer) {
static int kTimeout = 250000; // be responsive on signal
status_t err;
ssize_t trackIdx = -1;
uint32_t debugNumFrames = 0;
int64_t startWhenNsec = systemTime(CLOCK_MONOTONIC);
int64_t endWhenNsec = startWhenNsec + seconds_to_nanoseconds(gTimeLimitSec);
Vector<sp<ABuffer> > buffers;
err = encoder->getOutputBuffers(&buffers);
if (err != NO_ERROR) {
fprintf(stderr, "Unable to get output buffers (err=%d)\n", err);
return err;
}
// This is set by the signal handler.
gStopRequested = false;
// Run until we're signaled.
while (!gStopRequested) {
size_t bufIndex, offset, size;
int64_t ptsUsec;
uint32_t flags;
if (systemTime(CLOCK_MONOTONIC) > endWhenNsec) {
if (gVerbose) {
printf("Time limit reached\n");
}
break;
}
ALOGV("Calling dequeueOutputBuffer");
err = encoder->dequeueOutputBuffer(&bufIndex, &offset, &size, &ptsUsec,
&flags, kTimeout);
ALOGV("dequeueOutputBuffer returned %d", err);
switch (err) {
case NO_ERROR:
// got a buffer
if ((flags & MediaCodec::BUFFER_FLAG_CODECCONFIG) != 0) {
// ignore this -- we passed the CSD into MediaMuxer when
// we got the format change notification
ALOGV("Got codec config buffer (%u bytes); ignoring", size);
size = 0;
}
if (size != 0) {
ALOGV("Got data in buffer %d, size=%d, pts=%lld",
bufIndex, size, ptsUsec);
CHECK(trackIdx != -1);
// If the virtual display isn't providing us with timestamps,
// use the current time.
if (ptsUsec == 0) {
ptsUsec = systemTime(SYSTEM_TIME_MONOTONIC) / 1000;
}
// The MediaMuxer docs are unclear, but it appears that we
// need to pass either the full set of BufferInfo flags, or
// (flags & BUFFER_FLAG_SYNCFRAME).
err = muxer->writeSampleData(buffers[bufIndex], trackIdx,
ptsUsec, flags);
if (err != NO_ERROR) {
fprintf(stderr, "Failed writing data to muxer (err=%d)\n",
err);
return err;
}
debugNumFrames++;
}
err = encoder->releaseOutputBuffer(bufIndex);
if (err != NO_ERROR) {
fprintf(stderr, "Unable to release output buffer (err=%d)\n",
err);
return err;
}
if ((flags & MediaCodec::BUFFER_FLAG_EOS) != 0) {
// Not expecting EOS from SurfaceFlinger. Go with it.
ALOGD("Received end-of-stream");
gStopRequested = false;
}
break;
case -EAGAIN: // INFO_TRY_AGAIN_LATER
ALOGV("Got -EAGAIN, looping");
break;
case INFO_FORMAT_CHANGED: // INFO_OUTPUT_FORMAT_CHANGED
{
// format includes CSD, which we must provide to muxer
ALOGV("Encoder format changed");
sp<AMessage> newFormat;
encoder->getOutputFormat(&newFormat);
trackIdx = muxer->addTrack(newFormat);
ALOGV("Starting muxer");
err = muxer->start();
if (err != NO_ERROR) {
//.........这里部分代码省略.........
示例2: runEncoder
//.........这里部分代码省略.........
// The MediaMuxer docs are unclear, but it appears that we
// need to pass either the full set of BufferInfo flags, or
// (flags & BUFFER_FLAG_SYNCFRAME).
err = muxer->writeSampleData(buffers[bufIndex], videoTrackIdx,
ptsUsec, flags);
if (err != NO_ERROR) {
fprintf(stderr, "Failed writing data to muxer (err=%d)\n",
err);
return err;
}
debugNumFrames++;
}
err = videoEncoder->releaseOutputBuffer(bufIndex);
if (err != NO_ERROR) {
fprintf(stderr, "Unable to release output buffer (err=%d)\n",
err);
return err;
}
if ((flags & MediaCodec::BUFFER_FLAG_EOS) != 0) {
// Not expecting EOS from SurfaceFlinger. Go with it.
ALOGV("Received end-of-stream");
gStopRequested = false;
}
break;
case -EAGAIN: // INFO_TRY_AGAIN_LATER
ALOGV("Got -EAGAIN, looping");
break;
case INFO_FORMAT_CHANGED: // INFO_OUTPUT_FORMAT_CHANGED
{
// format includes CSD, which we must provide to muxer
ALOGV("Encoder format changed");
sp<AMessage> newFormat;
videoEncoder->getOutputFormat(&newFormat);
videoTrackIdx = muxer->addTrack(newFormat);
if (++tracksAdded >= (gRecordAudio ? 2 : 1)) {
ALOGV("Starting muxer");
err = muxer->start();
if (err != NO_ERROR) {
fprintf(stderr, "Unable to start muxer (err=%d)\n", err);
return err;
}
}
}
break;
case INFO_OUTPUT_BUFFERS_CHANGED: // INFO_OUTPUT_BUFFERS_CHANGED
// not expected for an encoder; handle it anyway
ALOGV("Encoder buffers changed");
err = videoEncoder->getOutputBuffers(&buffers);
if (err != NO_ERROR) {
fprintf(stderr,
"Unable to get new output buffers (err=%d)\n", err);
return err;
}
break;
case INVALID_OPERATION:
fprintf(stderr, "Request for encoder buffer failed\n");
return err;
default:
fprintf(stderr,
"Got weird result %d from dequeueOutputBuffer\n", err);
return err;
}
if (gRecordAudio) {
ALOGV("Calling dequeueOutputBuffer for audioEncoder");
err = audioEncoder->dequeueOutputBuffer(&bufIndex, &offset, &size, &ptsUsec,
开发者ID:EvoMagix,项目名称:platform_frameworks_base,代码行数:67,代码来源:android_media_ScreenRecorder_ScreenRecorderImpl.cpp