freshplayerplugin icon indicating copy to clipboard operation
freshplayerplugin copied to clipboard

advice on fixing https://gitlab.com/Mis012/flashplayer-standalone to make it work with freshplayer

Open Mis012 opened this issue 4 years ago • 9 comments

Hi,
I have found https://github.com/idaunis/simple-linux-flash-embed and to my surprise, it works perfectly - but only with the native NPAPI flash plugin :(
I however plan to use this on armhf, so pepperflash is the only option
I have fixed the straight up crash, but now I am getting an all-white screen with working right-click menu that says "Movie not loaded".
Notably, I wasn't able to get the placeholder image to show up either (though looking at the code I don't see how it would do that).

Is there any chance that you might be able to help?

Mis012 avatar Oct 27 '20 16:10 Mis012

hmm, it seems I'm able to change the rendered "bgcolor"... so it does something

Mis012 avatar Oct 31 '20 22:10 Mis012

probably an issue with ignoring unrequested stream

Mis012 avatar Oct 31 '20 23:10 Mis012

Ok, got it to work to a point where the last needed hack is this:

diff --git a/src/ppb_url_loader.c b/src/ppb_url_loader.c
index 9690d83..8f930f9 100644
--- a/src/ppb_url_loader.c
+++ b/src/ppb_url_loader.c
@@ -241,10 +241,12 @@ open_temporary_file(void)
 {
     char *tmpfname;
     // TODO: make temp path configurable
-    tmpfname = g_strdup_printf("/tmp/FreshStreamXXXXXX");
-    int fd = mkstemp(tmpfname);
-    unlink(tmpfname);
-    g_free(tmpfname);
+//    tmpfname = g_strdup_printf("/tmp/FreshStreamXXXXXX");
+//    int fd = mkstemp(tmpfname);
+
+       int fd = open("/path/to/actual/file.swf", O_RDONLY);
+//    unlink(tmpfname);
+//    g_free(tmpfname);
     return fd;
 }

but as I understand it, freshplayer should try to capture the first unrequested stream and use that in order to behave just like NPAPI flash?

Mis012 avatar Nov 03 '20 15:11 Mis012

freshplayer should try to capture the first unrequested stream and use that in order to behave just like NPAPI flash?

Yes, as far as I remember. When NPAPI Flash instance is created, browser itself initiates a flash movie download. So the first stream plugin gets is the .swf file. With PPAPI, browser does nothing, and the plugin is requesting a download.

See https://github.com/i-rinat/freshplayerplugin/issues/153 and https://github.com/i-rinat/freshplayerplugin/commit/abe3d525c9bd858e8eb7aeb05fa5b53261ebcc46.

i-rinat avatar Nov 03 '20 19:11 i-rinat

ok, I have figured out the issue

there is a race condition, if the NPAPI "browser" doesn't stream the file fast enough (ideally in one call to Write), it seems either freshplayer or flash will give up

Mis012 avatar Nov 04 '20 17:11 Mis012

if I stream the file in one go like this:

	FILE *pp;
	char buffer[1977354];
	pp = fopen(filename,"rb");
	int len;
	while((len=fread(buffer, 1, sizeof(buffer), pp)) != 0) {
		pluginFuncs.writeready(instance, stream);
		pluginFuncs.write(instance, stream, 0, len, buffer);
	}
	fclose(pp);

where 1977354 is the file size, everything works with zero modifications to freshplayer

Mis012 avatar Nov 04 '20 17:11 Mis012

Speaking of file sizes. simple-linux-flash-embed seems to hardcode file size here: https://github.com/idaunis/simple-linux-flash-embed/blob/b7d6ea436470a87659a5b1e59b54480c0664c303/player.c#L364. Did you try to change 99782 to -1 there? It may be important to have either correct data size there or -1. Otherwise Flash may decide to stop getting SWF content when it gets 99782 bytes.

i-rinat avatar Nov 07 '20 12:11 i-rinat

no difference unfortunately :(

Mis012 avatar Nov 08 '20 14:11 Mis012

Try this patch:

diff --git a/player.c b/player.c
old mode 100755
new mode 100644
index 4925ec0..8690aa4
--- a/player.c
+++ b/player.c
@@ -226,7 +226,7 @@ switch (variable) {
 		*((int*)ret_value)= NPNVGtk2;
 		break;
 	case NPNVnetscapeWindow:
-		*((int*)ret_value)= PR_TRUE;
+		*((int*)ret_value)= None;
 		break;
 	default:
 		*((int*)ret_value)=PR_FALSE;
@@ -360,9 +360,9 @@ static NPWindow * npwindow_construct (GtkWidget *widget) {
 static NPStream * npstream_construct() {
     NPStream *stream = (NPStream *) malloc(sizeof(NPStream));
     
-    stream->url=strdup(URL);
+    stream->url=strdup("http://127.0.0.1/movie.swf");
     stream->ndata = 0;
-    stream->end = 99782;
+    stream->end = 0;
     stream->lastmodified= 1201822722;
     stream->notifyData = 0x00000000;
     stream->headers = NULL;
@@ -908,9 +908,11 @@ int main(int argc, char **argv)
 	char buffer[8192];
 	pp = fopen(argv[1],"rb");
 	int len;
+	int offset = 0;
 	while((len=fread(buffer, 1, sizeof(buffer), pp)) != 0) {
 		pluginFuncs.writeready(instance, stream);
-		pluginFuncs.write(instance, stream, 0, len, buffer);
+		pluginFuncs.write(instance, stream, offset, len, buffer);
+		offset += len;
 	}
 	fclose(pp);
 

The only essential part are: url being URL, and correct values of offset. Looks like NPAPI Flash ignored offsets, but I for some reason decided that if there is a parameter, I must honor it. I don't know for sure why URL matters, but it's something inside PPAPI Flash itself. If ->url is not an URL, it just doesn't try to load a movie.

stream->end doesn't seem to change anything, but freshplayerplugin converts 0 to -1, which is what in PPAPI "language" means that size is not known in advance.

NPNVnetscapeWindow is not really required too, but plugin expects there a browser window handle, not a boolean. Setting it to None prevents BadWindow errors (code 3).

i-rinat avatar Nov 18 '20 00:11 i-rinat