Skip to content

Commit

Permalink
Fix parsing of Display Definition Segment in DVB subtitles and use the
Browse files Browse the repository at this point in the history
associated information to properly render standard definition subtitles
transmitted with an HD stream.

At some point I'll revisit the libavcodec elements and submit upstream
again. Closes #8061


git-svn-id: http://svn.mythtv.org/svn/trunk@26090 7dbf422c-18fa-0310-86e9-fd20926502f2
  • Loading branch information
Mark Kendall committed Sep 3, 2010
1 parent 8605e67 commit 14bea95
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 21 deletions.
4 changes: 4 additions & 0 deletions mythtv/external/FFmpeg/libavcodec/avcodec.h
Original file line number Diff line number Diff line change
Expand Up @@ -2935,6 +2935,10 @@ typedef struct AVSubtitleRect {
int w; ///< width of pict, undefined when pict is not set
int h; ///< height of pict, undefined when pict is not set
int nb_colors; ///< number of colors in pict, undefined when pict is not set
int display_x; ///< top left corner of region into which pict is displayed
int display_y; ///< top left corner of region into which pict is displayed
int display_w; ///< width of region into which pict is displayed
int display_h; ///< height of region into which pict is displayed

/**
* data+linesize for the bitmap of this subtitle.
Expand Down
20 changes: 12 additions & 8 deletions mythtv/external/FFmpeg/libavcodec/dvbsubdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1344,18 +1344,12 @@ static int dvbsub_display_end_segment(AVCodecContext *avctx, const uint8_t *buf,
DVBSubCLUT *clut;
uint32_t *clut_table;
int i;
int offset_x=0, offset_y=0;

sub->rects = NULL;
sub->start_display_time = 0;
sub->end_display_time = ctx->time_out * 1000;
sub->format = 0;

if (display_def) {
offset_x = display_def->x;
offset_y = display_def->y;
}

sub->num_rects = ctx->display_list_size;

if (sub->num_rects > 0){
Expand All @@ -1373,10 +1367,20 @@ static int dvbsub_display_end_segment(AVCodecContext *avctx, const uint8_t *buf,
if (!region)
continue;

rect->x = display->x_pos + offset_x;
rect->y = display->y_pos + offset_y;
rect->x = display->x_pos;
rect->y = display->y_pos;
rect->w = region->width;
rect->h = region->height;
if (display_def) {
rect->display_x = display_def->x;
rect->display_y = display_def->y;
rect->display_w = display_def->width;
rect->display_h = display_def->height;
}
else {
rect->display_w = 720;
rect->display_h = 576;
}
rect->nb_colors = 16;
rect->type = SUBTITLE_BITMAP;
rect->pict.linesize[0] = region->width;
Expand Down
16 changes: 8 additions & 8 deletions mythtv/libs/libmythtv/subtitlescreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,10 @@ void SubtitleScreen::DisplayAVSubtitles(void)
// AVSubtitleRect's image data's not guaranteed to be 4 byte
// aligned.

QRect qrect(rect->x, rect->y, rect->w, rect->h);
QRect scaled = videoOut->GetImageRect(qrect);
QSize img_size(rect->w, rect->h);
QRect img_rect(rect->x, rect->y, rect->w, rect->h);
QRect display(rect->display_x, rect->display_y,
rect->display_w, rect->display_h);

// XSUB images are based on the original video size before
// they were converted to DivX. We need to guess the original
Expand All @@ -216,13 +218,11 @@ void SubtitleScreen::DisplayAVSubtitles(void)
(currentFrame->height <= 720) ? 720 : 1080;
int width = (currentFrame->width <= 720) ? 720 :
(currentFrame->width <= 1280) ? 1280 : 1920;
QMatrix m;
m.scale((float)currentFrame->width / width,
(float)currentFrame->height / height);
scaled = m.mapRect(scaled);
display = QRect(0, 0, width, height);
}

QImage qImage(rect->w, rect->h, QImage::Format_ARGB32);
QRect scaled = videoOut->GetImageRect(img_rect, &display);
QImage qImage(img_size, QImage::Format_ARGB32);
for (int y = 0; y < rect->h; ++y)
{
for (int x = 0; x < rect->w; ++x)
Expand All @@ -233,7 +233,7 @@ void SubtitleScreen::DisplayAVSubtitles(void)
}
}

if (scaled.size() != qrect.size())
if (scaled.size() != img_size)
{
qImage = qImage.scaled(scaled.width(), scaled.height(),
Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
Expand Down
18 changes: 14 additions & 4 deletions mythtv/libs/libmythtv/videooutbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1436,9 +1436,8 @@ void VideoOutput::CopyFrame(VideoFrame *to, const VideoFrame *from)
*/
}

QRect VideoOutput::GetImageRect(const QRect &rect)
QRect VideoOutput::GetImageRect(const QRect &rect, QRect *display)
{
QRect result = rect;
float hscale, vscale, tmp;
tmp = 0.0;
QRect visible_osd = GetVisibleOSDBounds(tmp, tmp, tmp);
Expand All @@ -1450,6 +1449,17 @@ QRect VideoOutput::GetImageRect(const QRect &rect)
float pixel_aspect = (float)video_size.width() /
(float)video_size.height();

QRect rect1 = rect;
if (display && display->isValid())
{
QMatrix m0;
m0.scale((float)image_width / (float)display->width(),
(float)image_height / (float)display->height());
rect1 = m0.mapRect(rect1);
rect1.translate(display->left(), display->top());
}
QRect result = rect1;

if (hasFullScreenOSD())
{
QRect dvr_rec = window.GetDisplayVideoRect();
Expand Down Expand Up @@ -1482,8 +1492,8 @@ QRect VideoOutput::GetImageRect(const QRect &rect)
hscale = pixel_aspect / image_aspect;
if (hscale < 0.99f || hscale > 1.01f)
{
result.setLeft((int)(((float)rect.left() * hscale) + 0.5f));
result.setWidth((int)(((float)rect.width() * hscale) + 0.5f));
result.setLeft((int)(((float)rect1.left() * hscale) + 0.5f));
result.setWidth((int)(((float)rect1.width() * hscale) + 0.5f));
}

result.translate(-visible_osd.left(), -visible_osd.top());
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/videooutbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ class VideoOutput

QString GetFilters(void) const;
/// \brief translates caption/dvd button rectangle into 'screen' space
QRect GetImageRect(const QRect &rect);
QRect GetImageRect(const QRect &rect, QRect *display = NULL);
QRect GetSafeRect(void);

protected:
Expand Down

0 comments on commit 14bea95

Please sign in to comment.