mirror of
https://github.com/tuxbox-neutrino/libstb-hal.git
synced 2025-08-27 15:33:00 +02:00
libeplayer3: initial attempt to unbreak ass/ssa subtitles
This commit is contained in:
@@ -55,7 +55,7 @@
|
||||
|
||||
#ifdef ASS_DEBUG
|
||||
|
||||
static short debug_level = 0;
|
||||
static short debug_level = 10;
|
||||
|
||||
#define ass_printf(level, fmt, x...) do { \
|
||||
if (debug_level >= level) printf("[%s:%s] " fmt, __FILE__, __FUNCTION__, ## x); } while (0)
|
||||
@@ -116,8 +116,8 @@ static unsigned char isContainerRunning = 0;
|
||||
static ASS_Library *ass_library;
|
||||
static ASS_Renderer *ass_renderer;
|
||||
|
||||
static float ass_font_scale = 0.7;
|
||||
static float ass_line_spacing = 0.7;
|
||||
static float ass_font_scale = 0.4; // was: 0.7
|
||||
static float ass_line_spacing = 0.4; // was: 0.7
|
||||
|
||||
static unsigned int screen_width = 0;
|
||||
static unsigned int screen_height = 0;
|
||||
@@ -592,7 +592,7 @@ int container_ass_init(Context_t *context)
|
||||
(int)(0.03 * screen_width ), (int)(0.03 * screen_width ) );
|
||||
}
|
||||
|
||||
ass_set_use_margins(ass_renderer, 0 );
|
||||
ass_set_use_margins(ass_renderer, 1);
|
||||
ass_set_font_scale(ass_renderer, (ass_font_scale * screen_height) / 240.0);
|
||||
|
||||
ass_set_hinting(ass_renderer, ASS_HINTING_LIGHT);
|
||||
|
@@ -427,12 +427,6 @@ static void FFMPEGThread(Context_t *context) {
|
||||
|
||||
if (av_read_frame(avContext, &packet) == 0 )
|
||||
{
|
||||
if (!packet.data) {
|
||||
ffmpeg_err("no data ->end of file reached ? \n");
|
||||
releaseMutex(FILENAME, __FUNCTION__,__LINE__);
|
||||
break;
|
||||
}
|
||||
|
||||
long long int pts;
|
||||
Track_t * videoTrack = NULL;
|
||||
Track_t * audioTrack = NULL;
|
||||
@@ -706,7 +700,7 @@ static void FFMPEGThread(Context_t *context) {
|
||||
if (duration > 0.0)
|
||||
{
|
||||
/* is there a decoder ? */
|
||||
if (avcodec_find_decoder(((AVStream*) subtitleTrack->stream)->codec->codec_id) != NULL)
|
||||
if (((AVStream*) subtitleTrack->stream)->codec->codec)
|
||||
{
|
||||
AVSubtitle sub;
|
||||
int got_sub_ptr;
|
||||
@@ -739,41 +733,41 @@ static void FFMPEGThread(Context_t *context) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(((AVStream*)subtitleTrack->stream)->codec->codec_id == AV_CODEC_ID_SSA)
|
||||
{
|
||||
SubtitleData_t data;
|
||||
if(((AVStream*)subtitleTrack->stream)->codec->codec_id == AV_CODEC_ID_SSA)
|
||||
{
|
||||
SubtitleData_t data;
|
||||
|
||||
ffmpeg_printf(10, "videoPts %lld\n", currentVideoPts);
|
||||
ffmpeg_printf(10, "videoPts %lld\n", currentVideoPts);
|
||||
|
||||
data.data = packet.data;
|
||||
data.len = packet.size;
|
||||
data.extradata = subtitleTrack->extraData;
|
||||
data.extralen = subtitleTrack->extraSize;
|
||||
data.pts = pts;
|
||||
data.duration = duration;
|
||||
data.data = packet.data;
|
||||
data.len = packet.size;
|
||||
data.extradata = subtitleTrack->extraData;
|
||||
data.extralen = subtitleTrack->extraSize;
|
||||
data.pts = pts;
|
||||
data.duration = duration;
|
||||
|
||||
context->container->assContainer->Command(context, CONTAINER_DATA, &data);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* hopefully native text ;) */
|
||||
context->container->assContainer->Command(context, CONTAINER_DATA, &data);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* hopefully native text ;) */
|
||||
|
||||
unsigned char* line = text_to_ass((char *)packet.data,pts/90,duration);
|
||||
ffmpeg_printf(50,"text line is %s\n",(char *)packet.data);
|
||||
ffmpeg_printf(50,"Sub line is %s\n",line);
|
||||
ffmpeg_printf(20, "videoPts %lld %f\n", currentVideoPts,currentVideoPts/90000.0);
|
||||
SubtitleData_t data;
|
||||
data.data = line;
|
||||
data.len = strlen((char*)line);
|
||||
data.extradata = (unsigned char *) DEFAULT_ASS_HEAD;
|
||||
data.extralen = strlen(DEFAULT_ASS_HEAD);
|
||||
data.pts = pts;
|
||||
data.duration = duration;
|
||||
unsigned char* line = text_to_ass((char *)packet.data,pts/90,duration);
|
||||
ffmpeg_printf(50,"text line is %s\n",(char *)packet.data);
|
||||
ffmpeg_printf(50,"Sub line is %s\n",line);
|
||||
ffmpeg_printf(20, "videoPts %lld %f\n", currentVideoPts,currentVideoPts/90000.0);
|
||||
SubtitleData_t data;
|
||||
data.data = line;
|
||||
data.len = strlen((char*)line);
|
||||
data.extradata = (unsigned char *) DEFAULT_ASS_HEAD;
|
||||
data.extralen = strlen(DEFAULT_ASS_HEAD);
|
||||
data.pts = pts;
|
||||
data.duration = duration;
|
||||
|
||||
context->container->assContainer->Command(context, CONTAINER_DATA, &data);
|
||||
free(line);
|
||||
context->container->assContainer->Command(context, CONTAINER_DATA, &data);
|
||||
free(line);
|
||||
}
|
||||
}
|
||||
} /* duration */
|
||||
}
|
||||
@@ -818,12 +812,15 @@ static void FFMPEGThread(Context_t *context) {
|
||||
//ffmpeg_err("writing data to teletext fifo failed\n");
|
||||
}
|
||||
}
|
||||
} else { // av_read_frame failed
|
||||
ffmpeg_err("no data ->end of file reached ? \n");
|
||||
av_free_packet(&packet);
|
||||
releaseMutex(FILENAME, __FUNCTION__,__LINE__);
|
||||
break; // while
|
||||
}
|
||||
|
||||
av_free_packet(&packet);
|
||||
|
||||
releaseMutex(FILENAME, __FUNCTION__,__LINE__);
|
||||
|
||||
} /* while */
|
||||
|
||||
if (swr)
|
||||
@@ -924,10 +921,10 @@ int container_ffmpeg_init(Context_t *context, char * filename)
|
||||
terminating = 0;
|
||||
latestPts = 0;
|
||||
isContainerRunning = 1;
|
||||
return container_ffmpeg_update_tracks(context, filename);
|
||||
return container_ffmpeg_update_tracks(context, filename, 1);
|
||||
}
|
||||
|
||||
int container_ffmpeg_update_tracks(Context_t *context, char *filename)
|
||||
int container_ffmpeg_update_tracks(Context_t *context, char *filename, int initial)
|
||||
{
|
||||
if (terminating)
|
||||
return cERR_CONTAINER_FFMPEG_NO_ERROR;
|
||||
@@ -942,13 +939,14 @@ int container_ffmpeg_update_tracks(Context_t *context, char *filename)
|
||||
int teletextId = -1;
|
||||
|
||||
context->manager->audio->Command(context, MANAGER_GET_TRACK, &audioTrack);
|
||||
context->manager->subtitle->Command(context, MANAGER_GET_TRACK, &subtitleTrack);
|
||||
if (initial)
|
||||
context->manager->subtitle->Command(context, MANAGER_GET_TRACK, &subtitleTrack);
|
||||
context->manager->dvbsubtitle->Command(context, MANAGER_GET_TRACK, &dvbsubtitleTrack);
|
||||
context->manager->teletext->Command(context, MANAGER_GET_TRACK, &teletextTrack);
|
||||
|
||||
if (audioTrack)
|
||||
audioId = ((AVStream *) (audioTrack->stream))->id;
|
||||
if (subtitleTrack)
|
||||
if (initial && subtitleTrack)
|
||||
subtitleId = ((AVStream *) (subtitleTrack->stream))->id;
|
||||
if (dvbsubtitleTrack)
|
||||
dvbsubtitleId = ((AVStream *) (dvbsubtitleTrack->stream))->id;
|
||||
@@ -961,7 +959,7 @@ int container_ffmpeg_update_tracks(Context_t *context, char *filename)
|
||||
context->manager->video->Command(context, MANAGER_DEL, NULL);
|
||||
if (context->manager->audio)
|
||||
context->manager->audio->Command(context, MANAGER_DEL, NULL);
|
||||
if (context->manager->subtitle)
|
||||
if (initial && context->manager->subtitle)
|
||||
context->manager->subtitle->Command(context, MANAGER_DEL, NULL);
|
||||
if (context->manager->dvbsubtitle)
|
||||
context->manager->dvbsubtitle->Command(context, MANAGER_DEL, NULL);
|
||||
@@ -1319,11 +1317,21 @@ int container_ffmpeg_update_tracks(Context_t *context, char *filename)
|
||||
if (context->manager->dvbsubtitle->Command(context, MANAGER_ADD, &track) < 0) {
|
||||
ffmpeg_err("failed to add dvbsubtitle track %d\n", n);
|
||||
}
|
||||
} else if (context->manager->subtitle)
|
||||
if (context->manager->subtitle->Command(context, MANAGER_ADD, &track) < 0) {
|
||||
} else if (initial && context->manager->subtitle) {
|
||||
if (!stream->codec->codec) {
|
||||
stream->codec->codec = avcodec_find_decoder(stream->codec->codec_id);
|
||||
if (!stream->codec->codec)
|
||||
ffmpeg_err("avcodec_find_decoder failed for subtitle track %d\n", n);
|
||||
else if (avcodec_open2(stream->codec, stream->codec->codec, NULL)) {
|
||||
ffmpeg_err("avcodec_open2 failed for subtitle track %d\n", n);
|
||||
stream->codec->codec = NULL;
|
||||
}
|
||||
}
|
||||
if (stream->codec->codec && context->manager->subtitle->Command(context, MANAGER_ADD, &track) < 0) {
|
||||
/* konfetti: fixme: is this a reason to return with error? */
|
||||
ffmpeg_err("failed to add subtitle track %d\n", n);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
@@ -21,11 +21,11 @@
|
||||
/* Includes */
|
||||
/* ***************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netdb.h>
|
||||
#include <sys/types.h>
|
||||
@@ -384,15 +384,23 @@ static int SrtGetSubtitle(Context_t *context, char * Filename) {
|
||||
return cERR_SRT_NO_ERROR;
|
||||
}
|
||||
|
||||
static int SrtOpenSubtitle(Context_t *context __attribute__((unused)), int trackid) {
|
||||
static int SrtOpenSubtitle(Context_t *context __attribute__((unused)), int pid) {
|
||||
srt_printf(10, "\n");
|
||||
|
||||
if(trackid < TEXTSRTOFFSET || (trackid % TEXTSRTOFFSET) >= TrackCount) {
|
||||
if(pid < TEXTSRTOFFSET) {
|
||||
srt_err("trackid not for us\n");
|
||||
return cERR_SRT_ERROR;
|
||||
}
|
||||
|
||||
trackid %= TEXTSRTOFFSET;
|
||||
int trackid;
|
||||
for (trackid = 0; trackid < TrackCount; trackid++)
|
||||
if (Tracks[trackid].Id == pid)
|
||||
break;
|
||||
|
||||
if(trackid == TrackCount) {
|
||||
srt_err("trackid not for us\n");
|
||||
return cERR_SRT_ERROR;
|
||||
}
|
||||
|
||||
srt_printf(10, "%s\n", Tracks[trackid].File);
|
||||
|
||||
|
@@ -47,7 +47,7 @@
|
||||
|
||||
#ifdef SSA_DEBUG
|
||||
|
||||
static short debug_level = 0;
|
||||
static short debug_level = 10;
|
||||
|
||||
#define ssa_printf(level, fmt, x...) do { \
|
||||
if (debug_level >= level) printf("[%s:%s] " fmt, FILENAME, __FUNCTION__, ## x); } while (0)
|
||||
@@ -263,7 +263,6 @@ static void SsaManagerDel(Context_t * context __attribute__((unused))) {
|
||||
for (i = 0; i < TrackCount; i++) {
|
||||
if (Tracks[i].File != NULL)
|
||||
free(Tracks[i].File);
|
||||
|
||||
Tracks[i].File = NULL;
|
||||
}
|
||||
free(Tracks);
|
||||
@@ -386,15 +385,24 @@ static int SsaGetSubtitle(Context_t *context, char * Filename) {
|
||||
|
||||
return cERR_SSA_NO_ERROR;
|
||||
}
|
||||
static int SsaOpenSubtitle(Context_t *context __attribute__((unused)), int trackid) {
|
||||
|
||||
static int SsaOpenSubtitle(Context_t *context __attribute__((unused)), int pid) {
|
||||
ssa_printf(10, "\n");
|
||||
|
||||
if(trackid < TEXTSSAOFFSET || (trackid % TEXTSSAOFFSET) >= TrackCount ) {
|
||||
if(pid < TEXTSSAOFFSET) {
|
||||
ssa_err("trackid not for us\n");
|
||||
return cERR_SSA_ERROR;
|
||||
}
|
||||
|
||||
trackid %= TEXTSSAOFFSET;
|
||||
int trackid;
|
||||
for (trackid = 0; trackid < TrackCount; trackid++)
|
||||
if (Tracks[trackid].Id == pid)
|
||||
break;
|
||||
|
||||
if(trackid == TrackCount) {
|
||||
ssa_err("trackid not for us\n");
|
||||
return cERR_SSA_ERROR;
|
||||
}
|
||||
|
||||
ssa_printf(10, "%s\n", Tracks[trackid].File);
|
||||
|
||||
|
Reference in New Issue
Block a user