Skip to content

Commit

Permalink
videoscrobble: Pass video origin as third argument to scrobble callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
andoma committed Sep 8, 2016
1 parent ab18103 commit b6dd45b
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 21 deletions.
13 changes: 9 additions & 4 deletions plugin_examples/videoscrobbling/videoscrobbling_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,29 +40,34 @@
This can be used to query current position, etc during pause/resume
Also the origin item (the item that the video was started from, on the
"previous page" so to say) is also available as a third argument
*/

var videoscrobbler = require('movian/videoscrobbler');

var vs = new videoscrobbler.VideoScrobbler();

vs.onstart = function(data, prop) {
vs.onstart = function(data, prop, origin) {
print("Started playback session: " + data.id + " at position " + prop.currenttime + " (seconds)");
print(JSON.stringify(data, null, 4));
print("The filename is: " + origin.filename);
require('movian/prop').print(origin);
}

vs.onstop = function(data, prop) {
vs.onstop = function(data, prop, origin) {
print("Stopped playback session: " + data.id + " at position " + prop.currenttime + " (seconds)");
print(JSON.stringify(data, null, 4));
}

vs.onpause = function(data, prop) {
vs.onpause = function(data, prop, origin) {
print("Paused playback session: " + data.id + " at position " + prop.currenttime + " (seconds)");
print(JSON.stringify(data, null, 4));
}

vs.onresume = function(data, prop) {
vs.onresume = function(data, prop, origin) {
print("Resumed playback session: " + data.id + " at position " + prop.currenttime + " (seconds)");
print(JSON.stringify(data, null, 4));
}
11 changes: 6 additions & 5 deletions res/ecmascript/modules/movian/videoscrobbler.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ var P = require('movian/prop');
exports.VideoScrobbler = function() {

this.paused = false;
this.hook = hook.register('videoscrobble', function(event, data, prop) {
this.hook = hook.register('videoscrobble', function(event, data, prop, origin) {
prop = P.makeProp(prop);
origin = P.makeProp(origin);

this.paused = prop.playstatus == 'pause';

switch(event) {
case 'start':
if(typeof(this.onstart) === 'function')
this.onstart(data, prop);
this.onstart(data, prop, origin);

P.subscribeValue(prop.playstatus, function(val) {
var paused = val === 'pause';
Expand All @@ -22,10 +23,10 @@ exports.VideoScrobbler = function() {
this.paused = paused;
if(paused) {
if(typeof(this.onpause) === 'function')
this.onpause(data, prop);
this.onpause(data, prop, origin);
} else {
if(typeof(this.onresume) === 'function')
this.onresume(data, prop);
this.onresume(data, prop, origin);
}
}.bind(this), {
autoDestroy: true
Expand All @@ -34,7 +35,7 @@ exports.VideoScrobbler = function() {

case 'stop':
if(typeof(this.onstop) === 'function')
this.onstop(data, prop);
this.onstop(data, prop, origin);
break;
}

Expand Down
3 changes: 2 additions & 1 deletion src/arch/rpi/rpi_tv.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ static int respond;


static void
rpi_tv_vpi(vpi_op_t op, struct htsmsg *info, struct prop *p)
rpi_tv_vpi(vpi_op_t op, struct htsmsg *info, struct prop *p,
struct prop *origin)
{
if(!respond)
return;
Expand Down
9 changes: 7 additions & 2 deletions src/ecmascript/es_scrobble.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ typedef struct video_scrobble_aux {
vpi_op_t op;
struct htsmsg *info;
struct prop *p;
struct prop *origin;
} video_scrobble_aux_t;


Expand Down Expand Up @@ -56,7 +57,8 @@ video_scrobble_push_args(duk_context *duk, void *opaque)
}

es_stprop_push(duk, vsa->p);
return 3;
es_stprop_push(duk, vsa->origin);
return 4;
}


Expand All @@ -67,6 +69,7 @@ scrobble_video_task(void *aux)
es_hook_invoke("videoscrobble", video_scrobble_push_args, vsa);
htsmsg_release(vsa->info);
prop_ref_dec(vsa->p);
prop_ref_dec(vsa->origin);
free(vsa);
}

Expand All @@ -75,12 +78,14 @@ scrobble_video_task(void *aux)
*
*/
static void
es_scrobble_video(vpi_op_t op, struct htsmsg *info, struct prop *p)
es_scrobble_video(vpi_op_t op, struct htsmsg *info, struct prop *p,
struct prop *origin)
{
video_scrobble_aux_t *vsa = malloc(sizeof(video_scrobble_aux_t));
vsa->op = op;
vsa->info = htsmsg_copy(info);
vsa->p = prop_ref_inc(p);
vsa->origin = prop_follow(origin);

task_run(scrobble_video_task, vsa);
}
Expand Down
10 changes: 6 additions & 4 deletions src/fileaccess/fa_video.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ video_player_loop(AVFormatContext *fctx, media_codec_t **cwvec,
fa_handle_t *fh,
int resume_mode,
const char *title,
htsmsg_t *vpi)
htsmsg_t *vpi,
prop_t *origin)
{
media_buf_t *mb = NULL;
media_queue_t *mq = NULL;
Expand Down Expand Up @@ -203,7 +204,7 @@ video_player_loop(AVFormatContext *fctx, media_codec_t **cwvec,
if(fctx->duration != AV_NOPTS_VALUE)
htsmsg_add_dbl(vpi, "duration", fctx->duration / 1000000.0f);

video_playback_info_invoke(VPI_START, vpi, mp->mp_prop_root);
video_playback_info_invoke(VPI_START, vpi, mp->mp_prop_root, origin);

const int64_t offset = fctx->start_time != PTS_UNSET ? fctx->start_time : 0;

Expand Down Expand Up @@ -885,9 +886,10 @@ be_file_playvideo_fh(const char *url, media_pipe_t *mp,
event_t *e;
e = video_player_loop(fctx, cwvec, mp, va.flags, errbuf, errlen,
va.canonical_url, freetype_context, si, ci,
cwvec_size, fh, va.resume_mode, va.title, vpi);
cwvec_size, fh, va.resume_mode, va.title, vpi,
va.origin);

video_playback_info_invoke(VPI_STOP, vpi, mp->mp_prop_root);
video_playback_info_invoke(VPI_STOP, vpi, mp->mp_prop_root, va.origin);
htsmsg_release(vpi);

seek_index_destroy(si);
Expand Down
3 changes: 2 additions & 1 deletion src/ipc/libcec.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,8 @@ activate_self(void *aux)


static void
libcec_vpi(vpi_op_t op, struct htsmsg *info, struct prop *p)
libcec_vpi(vpi_op_t op, struct htsmsg *info, struct prop *p,
struct prop *origin)
{
if(!conn)
return;
Expand Down
5 changes: 3 additions & 2 deletions src/video/video_playback.c
Original file line number Diff line number Diff line change
Expand Up @@ -1035,9 +1035,10 @@ register_video_playback_info_handler(video_playback_info_handler_t *vpih)


void
video_playback_info_invoke(vpi_op_t op, struct htsmsg *vpi, struct prop *p)
video_playback_info_invoke(vpi_op_t op, struct htsmsg *vpi, struct prop *p,
struct prop *origin)
{
video_playback_info_handler_t *vpih;
LIST_FOREACH(vpih, &vpi_handlers, link)
vpih->invoke(op, vpi, p);
vpih->invoke(op, vpi, p, origin);
}
6 changes: 4 additions & 2 deletions src/video/video_playback.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,15 @@ typedef enum {
} vpi_op_t;

typedef struct video_playback_info_handler {
void (*invoke)(vpi_op_t op, struct htsmsg *info, struct prop *mp_root);
void (*invoke)(vpi_op_t op, struct htsmsg *info, struct prop *mp_root,
struct prop *origin);
LIST_ENTRY(video_playback_info_handler) link;
} video_playback_info_handler_t;

void register_video_playback_info_handler(video_playback_info_handler_t *vpih);

void video_playback_info_invoke(vpi_op_t op, struct htsmsg *vpi, struct prop *p);
void video_playback_info_invoke(vpi_op_t op, struct htsmsg *vpi,
struct prop *p, struct prop *origin);

#define VPI_REGISTER(handler) \
static video_playback_info_handler_t handler ## _strct = { handler}; \
Expand Down

0 comments on commit b6dd45b

Please sign in to comment.