xref: /haiku/src/add-ons/media/media-add-ons/videowindow/VideoAddOn.cpp (revision 21258e2674226d6aa732321b6f8494841895af5f)
1 /*
2  * Copyright (C) 2006-2008 Marcus Overhagen <marcus@overhagen.de>. All rights reserved.
3  * Copyright (C) 2008 Maurice Kalinowski <haiku@kaldience.com>. All rights reserved.
4  *
5  * Distributed under the terms of the MIT License.
6  */
7 #include "VideoAddOn.h"
8 #include "VideoNode.h"
9 #include "VideoView.h"
10 #include "debug.h"
11 
12 
13 #include <stdio.h>
14 #include <string.h>
15 
16 
17 VideoWindowAddOn::VideoWindowAddOn(image_id id)
18 		: BMediaAddOn(id)
19 {
20 	CALLED();
21 
22 	fInputFormat.type = B_MEDIA_RAW_VIDEO;
23 	fInputFormat.u.raw_video = media_raw_video_format::wildcard;
24 
25 	fInfo.internal_id = 0;
26 	fInfo.name = strdup("VideoWindow Consumer");
27 	fInfo.info = strdup("This node displays a simple video window");
28 	fInfo.kinds = B_BUFFER_CONSUMER;
29 	fInfo.flavor_flags = 0;
30 	fInfo.possible_count = 0;
31 	fInfo.in_format_count = 1;
32 	fInfo.in_format_flags = 0;
33 	fInfo.in_formats = &fInputFormat;
34 	fInfo.out_format_count = 0;
35 	fInfo.out_formats = 0;
36 	fInfo.out_format_flags = 0;
37 }
38 
39 
40 VideoWindowAddOn::~VideoWindowAddOn()
41 {
42 }
43 
44 
45 
46 bool
47 VideoWindowAddOn::WantsAutoStart()
48 {
49 	CALLED();
50 	return false;
51 }
52 
53 
54 int32
55 VideoWindowAddOn::CountFlavors()
56 {
57 	CALLED();
58 	return 1;
59 }
60 
61 
62 status_t
63 VideoWindowAddOn::GetFlavorAt(int32 cookie, const flavor_info **flavorInfo)
64 {
65 	CALLED();
66 	if (cookie != 0)
67 		return B_BAD_INDEX;
68 	if (!flavorInfo || !*flavorInfo)
69 		return B_ERROR;
70 
71 	*flavorInfo = &fInfo;
72 	return B_OK;
73 }
74 
75 
76 BMediaNode*
77 VideoWindowAddOn::InstantiateNodeFor(const flavor_info *info, BMessage*, status_t *outError)
78 {
79 	CALLED();
80 	if (!outError)
81 		return NULL;
82 
83 	if (info->in_formats[0].type != B_MEDIA_RAW_VIDEO) {
84 		*outError = B_MEDIA_BAD_FORMAT;
85 		return NULL;
86 	}
87 
88 	BRect size;
89 	if (info->in_formats[0].u.raw_video.display.line_width != 0)
90 		size.right = info->in_formats[0].u.raw_video.display.line_width;
91 	else
92 		size.right = 320;
93 	if (info->in_formats[0].u.raw_video.display.line_count != 0)
94 		size.bottom = info->in_formats[0].u.raw_video.display.line_count;
95 	else
96 		size.bottom = 240;
97 
98 	VideoNode* node = new VideoNode("Video Node", this, info->internal_id);
99 
100 	return node;
101 }
102 
103 
104 extern "C" BMediaAddOn *make_media_addon(image_id id)
105 {
106 	return new VideoWindowAddOn(id);
107 }
108