Ich versuche, einen Frame an einen anderen Prozess zu senden, um ihn anzuzeigen. Ich verwende dranger tutorial02.SDL-Frame an einen anderen Prozess senden und anzeigen
Ich dachte daran, die SDL_Overlay-Struktur in Bytes nach dem Aufruf von sws_scale zu serialisieren, es an den anderen Prozess zu senden, deserialisieren und SDL_DisplayYUVOverlay aufzurufen, um es anzuzeigen.
Denken Sie, dass dies meine beste Wahl ist?
Wenn ja, ich bin diese Struktur harte Zeit, Serialisierung .. hier ist der Code:
size_t size_of_Overlay(SDL_Overlay *bmp) {
/*
* typedef struct {
*
* Uint32 format;
* int w, h;
* int planes;
* Uint16 *pitches;
* Uint8 **pixels;
* Uint32 hw_overlay:1; <- can I ignore it? cant point to a bit-field..
*
* } SDL_Overlay;
*/
// w,h,planes format pitches pixels
return sizeof(int)*3 + sizeof(Uint32) + sizeof(Uint16)*bmp->w + sizeof(Uint8)*bmp->h*3;
}
void overlay_to_buf(SDL_Overlay* bmp, char* buf) {
if(!bmp || !buf) {
perror("overlay_to_buf");
exit(1);
}
memcpy(buf, &bmp->format, sizeof(Uint32));
buf += sizeof(Uint32);
memcpy(buf, &bmp->w, sizeof(int));
buf += sizeof(int);
memcpy(buf, &bmp->h, sizeof(int));
buf += sizeof(int);
memcpy(buf, &bmp->planes, sizeof(int));
buf += sizeof(int);
memcpy(buf, bmp->pitches, sizeof(Uint16)*bmp->w);
buf += sizeof(Uint16)*bmp->w;
memcpy(buf, bmp->pixels[0], sizeof(Uint8)*bmp->h);
buf += sizeof(Uint8)*bmp->h;
memcpy(buf, bmp->pixels[1], sizeof(Uint8)*bmp->h);
buf += sizeof(Uint8)*bmp->h;
memcpy(buf, bmp->pixels[2], sizeof(Uint8)*bmp->h);
buf += sizeof(Uint8)*bmp->h;
}
void buf_to_overlay(SDL_Overlay *bmp, char* buf) {
if(!bmp || !buf) {
perror("buf_to_overlay");
exit(1);
}
memcpy(&bmp->format, buf, sizeof(Uint32));
buf += sizeof(Uint32);
memcpy(&bmp->w, buf, sizeof(int));
buf += sizeof(int);
memcpy(&bmp->h, buf, sizeof(int));
buf += sizeof(int);
memcpy(&bmp->planes, buf, sizeof(int));
buf += sizeof(int);
bmp->pitches = (Uint16*)malloc(sizeof(Uint16)*bmp->w);
memcpy(bmp->pitches, buf, sizeof(Uint16)*bmp->w);
buf += sizeof(Uint16)*bmp->w;
bmp->pixels[0] = (Uint8*)malloc(sizeof(Uint8)*bmp->h);
memcpy(bmp->pixels[0], buf, sizeof(Uint8)*bmp->h);
buf += sizeof(Uint8)*bmp->h;
bmp->pixels[1] = (Uint8*)malloc(sizeof(Uint8)*bmp->h);
memcpy(bmp->pixels[1], buf, sizeof(Uint8)*bmp->h);
buf += sizeof(Uint8)*bmp->h;
bmp->pixels[2] = (Uint8*)malloc(sizeof(Uint8)*bmp->h);
memcpy(bmp->pixels[2], buf, sizeof(Uint8)*bmp->h);
buf += sizeof(Uint8)*bmp->h;
}