xref: /haiku/src/add-ons/media/media-add-ons/video_producer_demo/AddOn.cpp (revision 4c8e85b316c35a9161f5a1c50ad70bc91c83a76f)
1 /*
2 	Copyright 1999, Be Incorporated.   All Rights Reserved.
3 	This file may be used under the terms of the Be Sample Code License.
4 */
5 #include <Autolock.h>
6 #include <MediaFormats.h>
7 #include <stdio.h>
8 #include <string.h>
9 #include <unistd.h>
10 
11 #include "AddOn.h"
12 #include "Producer.h"
13 
14 MediaAddOn::MediaAddOn(image_id imid)
15 	: BMediaAddOn(imid)
16 {
17 	/* Customize these parameters to match those of your node */
18 	fFlavorInfo.name = "Demo Video Producer";
19 	fFlavorInfo.info = "Demo Video Producer";
20 	fFlavorInfo.kinds = B_BUFFER_PRODUCER | B_CONTROLLABLE;
21 	fFlavorInfo.flavor_flags = 0;
22 	fFlavorInfo.internal_id = 0;
23 	fFlavorInfo.possible_count = 5; // limited to 5 instances (just for testing)
24 	fFlavorInfo.in_format_count = 0;
25 	fFlavorInfo.in_format_flags = 0;
26 	fFlavorInfo.in_formats = NULL;
27 	fFlavorInfo.out_format_count = 1;
28 	fFlavorInfo.out_format_flags = 0;
29 	fMediaFormat.type = B_MEDIA_RAW_VIDEO;
30 	fMediaFormat.u.raw_video = media_raw_video_format::wildcard;
31 	fMediaFormat.u.raw_video.interlace = 1;
32 	fMediaFormat.u.raw_video.display.format = B_RGB32;
33 	fFlavorInfo.out_formats = &fMediaFormat;
34 
35 	fInitStatus = B_OK;
36 }
37 
38 MediaAddOn::~MediaAddOn()
39 {
40 }
41 
42 
43 status_t
44 MediaAddOn::InitCheck(const char **out_failure_text)
45 {
46 	if (fInitStatus < B_OK) {
47 		*out_failure_text = "Unknown error";
48 		return fInitStatus;
49 	}
50 
51 	return B_OK;
52 }
53 
54 int32
55 MediaAddOn::CountFlavors()
56 {
57 	if (fInitStatus < B_OK)
58 		return fInitStatus;
59 
60 	/* This addon only supports a single flavor, as defined in the
61 	 * constructor */
62 	return 1;
63 }
64 
65 /*
66  * The pointer to the flavor received only needs to be valid between
67  * successive calls to BMediaAddOn::GetFlavorAt().
68  */
69 status_t
70 MediaAddOn::GetFlavorAt(int32 n, const flavor_info **out_info)
71 {
72 	if (fInitStatus < B_OK)
73 		return fInitStatus;
74 
75 	if (n != 0)
76 		return B_BAD_INDEX;
77 
78 	/* Return the flavor defined in the constructor */
79 	*out_info = &fFlavorInfo;
80 	return B_OK;
81 }
82 
83 BMediaNode *
84 MediaAddOn::InstantiateNodeFor(
85 		const flavor_info *info, BMessage *config, status_t *out_error)
86 {
87 	VideoProducer *node;
88 
89 	if (fInitStatus < B_OK)
90 		return NULL;
91 
92 	if (info->internal_id != fFlavorInfo.internal_id)
93 		return NULL;
94 
95 	/* At most one instance of the node should be instantiated at any given
96 	 * time. The locking for this restriction may be found in the VideoProducer
97 	 * class. */
98 	node = new VideoProducer(this, fFlavorInfo.name, fFlavorInfo.internal_id);
99 	if (node && (node->InitCheck() < B_OK)) {
100 		delete node;
101 		node = NULL;
102 	}
103 
104 	return node;
105 }
106 
107 BMediaAddOn *
108 make_media_addon(image_id imid)
109 {
110 	return new MediaAddOn(imid);
111 }
112