Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add flag checking for osd_onscreen variable
  • Loading branch information
andyb2000 committed May 22, 2013
1 parent 5cc1295 commit 3b112f7
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 20 deletions.
4 changes: 3 additions & 1 deletion README.md
Expand Up @@ -86,7 +86,9 @@ Once running, the following keys are mapped to actions:
'h' - toggle auto-switching to HD versions of programmes from an SD channel
' ' - pause/resume playback
'c' - display list of channels and current events to the console
'o' - To unsubscribe from current channel and go idle
- Also shows basic onscreen channel listing, whilst onscreen use
- n for next screen of channels, or p for previous screen of channels in listing
'o' - To toggle subscribe/unsubscribe (idle) on current channel
'a' - Cycle through available audio streams

pidvbip currently supports hardware decoding of H264 and MPEG-2 video
Expand Down
53 changes: 40 additions & 13 deletions osd.c
Expand Up @@ -254,7 +254,7 @@ static void osd_draw_window(struct osd_t* osd, int x, int y, int width, int heig
graphics_resource_fill(osd->img, x+width-2, y, 2, height, GRAPHICS_RGBA32(0xff,0xff,0xff,0xa0));
}

void osd_show_channellist(struct osd_t* osd, int offset, struct channel_t* p)
void osd_show_channellist(struct osd_t* osd, struct channel_t* p)
{
int32_t s=0;
uint32_t width,height;
Expand All @@ -264,8 +264,11 @@ void osd_show_channellist(struct osd_t* osd, int offset, struct channel_t* p)
uint32_t text_size = 40;
const char *text = "Channel Listing";
char ch_text[100];
int tmp_offset = 0;
uint32_t text_length = strlen(text);

fprintf(stderr,"osd_show_channellist\n");

height = osd->display_height;
width = osd->display_width / 3;

Expand All @@ -281,7 +284,13 @@ void osd_show_channellist(struct osd_t* osd, int offset, struct channel_t* p)
GRAPHICS_RGBA32(0xff,0xff,0xff,0xff), /* fg */
GRAPHICS_RGBA32(0x173,0x216,0x230,0x80), /* bg */
text, text_length, text_size);

if (channellist_offset > 0) {
fprintf(stderr,"channellist_offset %d\n",channellist_offset);
while (tmp_offset != channellist_offset) {
p = p->next;
tmp_offset += 1;
};
};
while (p) {
fprintf(stderr,"chan: %5d %5d - %s\n",p->id,p->lcn,p->name);
snprintf(ch_text,sizeof(ch_text),"%5d - %s",p->lcn,p->name);
Expand All @@ -304,7 +313,7 @@ void osd_show_channellist(struct osd_t* osd, int offset, struct channel_t* p)
graphics_update_displayed_resource(osd->img, 0, 0, 0, 0);
pthread_mutex_unlock(&osd->osd_mutex);
osd->osd_cleartime = get_time() + 20000;
osd_onscreen = 1;
osd->osd_state = OSD_CHANNELLIST;
}

static void osd_show_channelname(struct osd_t* osd, const char *text)
Expand All @@ -329,7 +338,6 @@ static void osd_show_channelname(struct osd_t* osd, const char *text)
GRAPHICS_RGBA32(0xff,0xff,0xff,0xff), /* fg */
GRAPHICS_RGBA32(0,0,0,0x80), /* bg */
text, text_length, text_size);
osd_onscreen = 1;
}

void osd_alert(struct osd_t* osd, char* text)
Expand Down Expand Up @@ -367,7 +375,6 @@ void osd_alert(struct osd_t* osd, char* text)
graphics_update_displayed_resource(osd->img, 0, 0, 0, 0);

pthread_mutex_unlock(&osd->osd_mutex);
osd_onscreen = 1;
}

static void osd_show_eventinfo(struct osd_t* osd, struct event_t* event)
Expand Down Expand Up @@ -441,7 +448,6 @@ static void osd_show_eventinfo(struct osd_t* osd, struct event_t* event)
render_paragraph(osd->img,iso_text,30,OSD_XMARGIN+350,800);
free(iso_text);
}
osd_onscreen = 1;
//fprintf(stderr,"Title: %s\n",event->title);
//fprintf(stderr,"Start: %04d-%02d-%02d %02d:%02d:%02d\n",start_time.tm_year+1900,start_time.tm_mon+1,start_time.tm_mday,start_time.tm_hour,start_time.tm_min,start_time.tm_sec);
//fprintf(stderr,"Stop: %04d-%02d-%02d %02d:%02d:%02d\n",stop_time.tm_year+1900,stop_time.tm_mon+1,stop_time.tm_mday,stop_time.tm_hour,stop_time.tm_min,stop_time.tm_sec);
Expand Down Expand Up @@ -473,7 +479,6 @@ static void osd_show_time(struct osd_t* osd)
GRAPHICS_RGBA32(0xff,0xff,0xff,0xff), /* fg */
GRAPHICS_RGBA32(0,0,0,0x80), /* bg */
str, strlen(str), 40);
osd_onscreen = 1;
}

void osd_show_info(struct osd_t* osd, int channel_id, int timeout)
Expand Down Expand Up @@ -508,7 +513,6 @@ void osd_show_info(struct osd_t* osd, int channel_id, int timeout)
}

event_free(event);
osd_onscreen = 1;
}

void osd_show_newchannel(struct osd_t* osd, int channel)
Expand Down Expand Up @@ -537,7 +541,6 @@ void osd_show_newchannel(struct osd_t* osd, int channel)
osd_show_channelname(osd,str);
graphics_update_displayed_resource(osd->img, 0, 0, 0, 0);
pthread_mutex_unlock(&osd->osd_mutex);
osd_onscreen = 1;
}

void osd_clear_newchannel(struct osd_t* osd)
Expand All @@ -550,7 +553,6 @@ void osd_clear_newchannel(struct osd_t* osd)
pthread_mutex_unlock(&osd->osd_mutex);

fprintf(stderr,"Clearing OSD...\n");
osd_onscreen = 0;
}

void osd_show_audio_menu(struct osd_t* osd, struct codecs_t* codecs, int audio_stream)
Expand All @@ -576,9 +578,6 @@ void osd_clear(struct osd_t* osd)
graphics_update_displayed_resource(osd->img, 0, 0, 0, 0);
pthread_mutex_unlock(&osd->osd_mutex);

/* Clear the variable to show osd is not on screen */
osd_onscreen = 0;

fprintf(stderr,"Clearing OSD...\n");

osd->osd_state = OSD_NONE;
Expand All @@ -604,3 +603,31 @@ void osd_update(struct osd_t* osd, int channel_id)
}
}
}

int osd_process_key(struct osd_t* osd, int c) {
/* process and check keypresses whilst osd shown */
int return_key = 0;

if (osd->osd_state == OSD_CHANNELLIST) {
switch (c) {
case 'n':
fprintf(stderr,"OSD key: n pressed -- next page (%d)\n",channellist_offset);
channellist_offset += 3;
fprintf(stderr,"OSD page (%d)\n",channellist_offset);
osd_show_channellist(osd, channels_return_struct());
return_key=1;
break;
case 'p':
fprintf(stderr,"OSD key: p pressed -- previous page\n");
if (channellist_offset > 3) {
channellist_offset -= 3;
} else {
channellist_offset = 0;
};
osd_show_channellist(osd, channels_return_struct());
return_key=1;
break;
};
};
return return_key;
}
9 changes: 5 additions & 4 deletions osd.h
Expand Up @@ -33,6 +33,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#define OSD_NONE 0
#define OSD_INFO 1
#define OSD_NEWCHANNEL 2
#define OSD_CHANNELLIST 3

struct osd_t {
GRAPHICS_RESOURCE_HANDLE img_blank;
Expand All @@ -54,17 +55,17 @@ void osd_init(struct osd_t* osd);
void osd_done(struct osd_t* osd);
void osd_alert(struct osd_t* osd, char* text);
void osd_show_info(struct osd_t* osd, int channel_id, int timeout);
void osd_show_channellist(struct osd_t* osd, int offset, struct channel_t* p);
void osd_show_channellist(struct osd_t* osd, struct channel_t* p);
void osd_show_newchannel(struct osd_t* osd, int channel);
void osd_clear(struct osd_t* osd);
void osd_clear_newchannel(struct osd_t* osd);
void osd_show_audio_menu(struct osd_t* osd, struct codecs_t* codecs, int audio_stream);
void osd_blank_video(struct osd_t* osd, int on_off);
void osd_update(struct osd_t* osd, int channel_id);
int osd_process_key(struct osd_t* osd, int c);

double get_time(void);
extern int *channellist_offset;

/* Onscreen variable, used to detect if OSD is shown */
int osd_onscreen;
double get_time(void);

#endif
16 changes: 14 additions & 2 deletions pidvbip.c
Expand Up @@ -58,6 +58,8 @@ struct htsp_t htsp;

static struct termios orig;

int * channellist_offset=0;

/* Messages to the HTSP receiver thread - low eight bits are a parameter */
#define MSG_CHANGE_AUDIO_STREAM 0x100

Expand Down Expand Up @@ -604,6 +606,14 @@ int main(int argc, char* argv[])
if (c != -1) {
DEBUGF("char read: 0x%08x ('%c')\n", c,(isalnum(c) ? c : ' '));

/* determine if we have an OSD shown, if we do we use a different keyset */
if (osd.osd_state != OSD_NONE) {
fprintf(stderr,"OSD present - Checking alternative keys\n");
if (osd_process_key(&osd,c) == 1) {
goto skip_keypress;
};
};

switch (c) {
case '0':
case '1':
Expand Down Expand Up @@ -643,8 +653,8 @@ int main(int argc, char* argv[])

case 'c':
channels_dump();
osd_show_channellist(&osd, 0, channels_return_struct());
/* osd_cleartime = get_time() + 40000; 40 second timeout */
channellist_offset=0;
osd_show_channellist(&osd, channels_return_struct());
break;

case 'h':
Expand Down Expand Up @@ -750,6 +760,8 @@ int main(int argc, char* argv[])
}
}

skip_keypress:

osd_update(&osd, user_channel_id);

if ((new_channel_timeout) && (get_time() >= new_channel_timeout)) {
Expand Down

0 comments on commit 3b112f7

Please sign in to comment.