Opened 5 years ago

Closed 4 years ago

#4458 closed defect (needs_more_info)

Segmentation fault on usage of libraries

Reported by: georgidobrich Owned by:
Priority: important Component: undetermined
Version: Keywords: crash SIGSEGV
Cc: michael Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

I have written a code which open 10 input and 10 rtp output context.
Then I use 10 threads to read data from a file and to stream it over the network
But I got "segmentation fault" and a core file.

The backtrace is:
Program terminated with signal SIGSEGV, Segmentation fault.
#0 memcpy_ssse3_rep () at ../sysdeps/i386/i686/multiarch/memcpy-ssse3-rep.S:1299
1299 ../sysdeps/i386/i686/multiarch/memcpy-ssse3-rep.S: No such file or directory.
(gdb) bt
#0
memcpy_ssse3_rep () at ../sysdeps/i386/i686/multiarch/memcpy-ssse3-rep.S:1299
#1 0x080acc14 in avio_read (s=0xb156be0, buf=0xb1c0189d "", size=16471) at libavformat/aviobuf.c:570
#2 0x081a35ba in append_packet_chunked (s=0xb156be0, pkt=0xb4801238, size=21644) at libavformat/utils.c:223
#3 0x0810a067 in mov_read_packet (s=0xb1579a0, pkt=0xb4801238) at libavformat/mov.c:4235
#4 0x081a4962 in ff_read_packet (s=0xb1579a0, pkt=0xb4801238) at libavformat/utils.c:665
#5 0x081a7e99 in read_frame_internal (s=s@entry=0xb1579a0, pkt=pkt@entry=0x917b180 <pkt+576>) at libavformat/utils.c:1318
#6 0x081a8ea3 in av_read_frame (s=<optimized out>, pkt=0x917b180 <pkt+576>) at libavformat/utils.c:1529
#7 0x080952f8 in worker_thread (Param=0xbfa4c650) at videogw.c:51
#8 0xb72e0efb in start_thread (arg=0xb4801b40) at pthread_create.c:309
#9 0xb721962e in clone () at ../sysdeps/unix/sysv/linux/i386/clone.S:129

The source coude I have used is:
/*

  • Copyright (c) 2013 Stefano Sabatini *
  • Permission is hereby granted, free of charge, to any person obtaining a copy
  • of this software and associated documentation files (the "Software"), to deal
  • in the Software without restriction, including without limitation the rights
  • to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  • copies of the Software, and to permit persons to whom the Software is
  • furnished to do so, subject to the following conditions: *
  • The above copyright notice and this permission notice shall be included in
  • all copies or substantial portions of the Software. *
  • THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  • IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  • FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  • THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  • LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  • OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  • THE SOFTWARE. */

/

  • @file
  • libavformat/libavcodec demuxing and muxing API example. *
  • Remux streams from one container format to another.
  • @example remuxing.c */

#include <libavutil/timestamp.h>
#include <libavformat/avformat.h>
#include <pthread.h>
#include <unistd.h>

#define MAX 10

AVOutputFormat *ofmt[MAX];
AVFormatContext *ifmt_ctx[MAX], *ofmt_ctx[MAX];
int video_idx[MAX];
AVPacket pkt[MAX];

void* worker_thread(void *Param)
{

int id = *((int*)Param);
int idx = video_idx[id];
int ret;

while (1)
{

ret = av_read_frame(ifmt_ctx[id], &pkt[id]);
if (ret < 0)

break;

if (pkt[id].stream_index != idx)

continue;

AVStream *in_stream = ifmt_ctx[id]->streams[pkt[id].stream_index];
AVStream *out_stream = ofmt_ctx[id]->streams[pkt[id].stream_index];

AVRational time_base = ifmt_ctx[id]->streams[idx]->time_base;

int time = 1000 * 1000 * strtof(av_ts2timestr(pkt[id].duration, &time_base), NULL);
usleep(time);

pkt[id].pts = av_rescale_q_rnd(pkt[id].pts, in_stream->time_base, out_stream->time_base, AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);
pkt[id].dts = av_rescale_q_rnd(pkt[id].dts, in_stream->time_base, out_stream->time_base, AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);
pkt[id].duration = av_rescale_q(pkt[id].duration, in_stream->time_base, out_stream->time_base);
pkt[id].pos = -1;

ret = av_interleaved_write_frame(ofmt_ctx[id], &pkt[id]);
if (ret < 0)
{

fprintf(stderr, "Error muxing packet thread %d\n", id);
break;

}

av_free_packet(&pkt[id]);

}

}

int main(int argc, char argv)
{

char *in_filename, out_filename[22];
int ret, i = 0;

memset(ofmt, 0, sizeof(ofmt));
memset(ofmt_ctx, 0, sizeof(ofmt_ctx));
memset(ifmt_ctx, 0, sizeof(ifmt_ctx));
memset(video_idx, -1, sizeof(video_idx));

in_filename = "/home/georgi/Downloads/video/IMG_0019.MOV";

av_register_all();
avformat_network_init();

for (i = 0; i < MAX; i++)
{

fprintf(stdout, "%d\n", i);

if ((ret = avformat_open_input(&ifmt_ctx[i], in_filename, 0, 0)) < 0)
{

fprintf(stderr, "Could not open input file '%s'", in_filename);
goto end;

}

if ((ret = avformat_find_stream_info(ifmt_ctx[i], 0)) < 0)
{

fprintf(stderr, "Failed to retrieve input stream information");
goto end;

}

ifmt_ctx[i]->flags |= AVFMT_FLAG_GENPTS;

sprintf(out_filename,"rtp://10.101.3.60:%d", 9078 + i);

avformat_alloc_output_context2(&ofmt_ctx[i], NULL, "rtp", out_filename);

if (!ofmt_ctx[i])
{

fprintf(stderr, "Could not create output context\n");
ret = AVERROR_UNKNOWN;
goto end;

}

ofmt[i] = ofmt_ctx[i]->oformat;

int k;
for (k = 0; k < ifmt_ctx[i]->nb_streams; k++)

{

if (ifmt_ctx[i]->streams[k]->codec->codec_type == AVMEDIA_TYPE_VIDEO)
{

AVStream *in_stream = ifmt_ctx[i]->streams[k];
AVStream *out_stream = avformat_new_stream(ofmt_ctx[i], in_stream->codec->codec);
if (!out_stream)
{

fprintf(stderr, "Failed allocating output stream\n");
ret = AVERROR_UNKNOWN;
goto end;

}

ret = avcodec_copy_context(out_stream->codec, in_stream->codec);
if (ret < 0)
{

fprintf(stderr, "Failed to copy context from input to output stream codec context\n");
goto end;

}
out_stream->codec->codec_tag = 0;
if (ofmt_ctx[i]->oformat->flags & AVFMT_GLOBALHEADER)

out_stream->codec->flags |= CODEC_FLAG_GLOBAL_HEADER;

video_idx[i] = k;

}

}

if (!(ofmt[i]->flags & AVFMT_NOFILE))
{

ret = avio_open(&ofmt_ctx[i]->pb, out_filename, AVIO_FLAG_WRITE);
if (ret < 0)
{

fprintf(stderr, "Could not open output file '%s'", out_filename);
goto end;

}

}

ret = avformat_write_header(ofmt_ctx[i], NULL);
if (ret < 0)
{

fprintf(stderr, "Error occurred when opening output file\n");
goto end;

}

}

pthread_t thread_ids[MAX];
for (i = 0; i < MAX; i++)

{

if ( 0 != pthread_create(&thread_ids[i], NULL, &worker_thread, (void*)&i) )

{

fprintf(stderr, "Could not create thread %d\n", i);
break;

}

}

for (i = 0; i < MAX; i++)

{

pthread_join(thread_ids[i], NULL);

}

end:

for (i = 0; i < MAX; i++)

{

av_write_trailer(ofmt_ctx[i]);

avformat_close_input(&ifmt_ctx[i]);

/* close output */
if (ofmt_ctx[i] && !(ofmt[i]->flags & AVFMT_NOFILE))

avio_closep(&ofmt_ctx[i]->pb);

avformat_free_context(ofmt_ctx[i]);

if (ret < 0 && ret != AVERROR_EOF)
{

fprintf(stderr, "Error occurred: %s\n", av_err2str(ret));
return 1;

}

}

return 0;

}

Change History (2)

comment:1 Changed 4 years ago by michael

  • Cc michael added

how exactly can this be reproduced ?

comment:2 Changed 4 years ago by cehoyos

  • Keywords crash SIGSEGV added
  • Priority changed from normal to important
  • Resolution set to needs_more_info
  • Status changed from new to closed

Please reopen this ticket if you can add the missing information.

Note: See TracTickets for help on using tickets.