return -1;
}
- while (1)
+ int c;
+
+ while ('q' != (c = getchar())) {
sleep(1);
+ }
+
+ simp_filter_close(f);
+
+ printf("main quit ok\n");
return 0;
}
return -EINVAL;
}
+int simp_avio_stop(simp_avio_t* io)
+{
+ if (io && io->ops && io->ops->stop)
+ return io->ops->stop(io);
+
+ return -EINVAL;
+}
+
int error;
int exit;
+ int flush;
pthread_t tid;
pthread_mutex_t mutex;
pthread_cond_t cond;
int (*open )(simp_avio_t* io, const char* path);
int (*close)(simp_avio_t* io);
int (*run )(simp_avio_t* io);
+ int (*stop )(simp_avio_t* io);
};
simp_frame_t* simp_frame_alloc();
int simp_avio_open (simp_avio_t** pio, const char* type, const char* path);
int simp_avio_close (simp_avio_t* io);
int simp_avio_run (simp_avio_t* io);
+int simp_avio_stop (simp_avio_t* io);
int simp_filter_open (simp_filter_t** pf);
int simp_filter_close (simp_filter_t* f);
io->exit = 1;
while (-1 != io->tid) {
pthread_cond_signal(&io->cond);
- pthread_cond_signal(&io->cond);
+ pthread_cond_wait(&io->cond, &io->mutex);
}
pthread_mutex_unlock(&io->mutex);
return NULL;
}
+static int _ffmpeg_input_stop(simp_avio_t* io)
+{
+ if (io) {
+ pthread_mutex_lock(&io->mutex);
+ io->exit = 1;
+ while (-1 != io->tid) {
+ pthread_cond_signal(&io->cond);
+ pthread_cond_wait(&io->cond, &io->mutex);
+ }
+ pthread_mutex_unlock(&io->mutex);
+ }
+
+ return 0;
+}
+
static int _ffmpeg_input_run(simp_avio_t* io)
{
if (pthread_create(&io->tid, NULL, __ffmpeg_input_run, io)) {
.open = _ffmpeg_input_open,
.close = _ffmpeg_input_close,
.run = _ffmpeg_input_run,
+ .stop = _ffmpeg_input_stop,
};
}
}
+
+ if (io->flush) {
+ pthread_mutex_lock(&io->mutex);
+ while(!scf_list_empty(&io->vout)) {
+ l = scf_list_head(&io->vout);
+ f = scf_list_data(l, simp_frame_t, list);
+
+ scf_list_del(&f->list);
+
+ scf_logd("priv->vidx: %d, frame->pts: %ld\n", priv->vidx, f->frame->pts);
+
+ if (0 == io->error) {
+
+ ret = __ffmpeg_encode(io, priv->vcodec_ctx, priv->vpkt, f->frame, priv->vidx);
+ if (ret < 0)
+ scf_loge("ret: %d, frame->pts: %ld\n", ret, f->frame->pts);
+
+ io->error = ret;
+ }
+
+ simp_frame_free(f);
+ f = NULL;
+ }
+
+ while (!scf_list_empty(&io->aout)) {
+ l = scf_list_head(&io->aout);
+ f = scf_list_data(l, simp_frame_t, list);
+
+ scf_list_del(&f->list);
+
+ if (0 == io->error) {
+ ret = av_audio_fifo_write(priv->afifo, (void**)f->frame->data, f->frame->nb_samples);
+ if (ret < 0)
+ scf_loge("ret: %d\n", ret);
+
+ io->error = ret;
+ }
+
+ simp_frame_free(f);
+ f = NULL;
+ }
+
+ while (av_audio_fifo_size(priv->afifo) > 0) {
+
+ if (0 == io->error) {
+ ret = av_audio_fifo_read(priv->afifo, (void**)priv->aframe->data, 1024);
+ if (ret < 0) {
+ scf_loge("ret: %d\n", ret);
+ io->error = ret;
+ break;
+ }
+
+ priv->nb_samples += priv->aframe->nb_samples;
+ priv->aframe->pts = priv->nb_samples;
+
+ scf_logd("aframe->pts: %ld\n", priv->aframe->pts);
+
+ ret = __ffmpeg_encode(io, priv->acodec_ctx, priv->apkt, priv->aframe, priv->aidx);
+ if (ret < 0) {
+ scf_loge("ret: %d\n", ret);
+ io->error = ret;
+ break;
+ }
+ }
+ }
+ pthread_mutex_unlock(&io->mutex);
+ }
+
end:
pthread_mutex_lock(&io->mutex);
io->tid = -1;