📄 nshxplayer.cpp
字号:
/* ***** BEGIN LICENSE BLOCK ***** * Source last modified: $Id: nsHXPlayer.cpp,v 1.5.2.6 2004/11/23 00:24:25 rggammon Exp $ * * * Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved. * * The contents of this file, and the files included with this file, * are subject to the current version of the RealNetworks Public * Source License (the "RPSL") available at * http://www.helixcommunity.org/content/rpsl unless you have licensed * the file under the current version of the RealNetworks Community * Source License (the "RCSL") available at * http://www.helixcommunity.org/content/rcsl, in which case the RCSL * will apply. You may also obtain the license terms directly from * RealNetworks. You may not use this file except in compliance with * the RPSL or, if you have a valid RCSL with RealNetworks applicable * to this file, the RCSL. Please see the applicable RPSL or RCSL for * the rights, obligations and limitations governing use of the * contents of the file. * * Alternatively, the contents of this file may be used under the * terms of the GNU General Public License Version 2 or later (the * "GPL") in which case the provisions of the GPL are applicable * instead of those above. If you wish to allow use of your version of * this file only under the terms of the GPL, and not to allow others * to use your version of this file under the terms of either the RPSL * or RCSL, indicate your decision by deleting the provisions above * and replace them with the notice and other provisions required by * the GPL. If you do not delete the provisions above, a recipient may * use your version of this file under the terms of any one of the * RPSL, the RCSL or the GPL. * * This file is part of the Helix DNA Technology. RealNetworks is the * developer of the Original Code and owns the copyrights in the * portions it created. * * This file, and the files included with this file, is distributed * and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY * KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS * ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET * ENJOYMENT OR NON-INFRINGEMENT. * * Technology Compatibility Kit Test Suite(s) Location: * http://www.helixcommunity.org/content/tck * * Contributor(s): * * ***** END LICENSE BLOCK ***** *//* XXXRGG: Undefine DEBUG so we don't pull in nsDebug stuff */#ifdef DEBUG# undef DEBUG#endif#include "nsHXPlayer.h"#include "hxbackend.h"#include "tokenizer.h"#include "asprintf.h"#include <stdlib.h>#include <stdio.h>nsHXPlayer::nsHXPlayer(CHXPlayerBackend *pBackend) : nsPluginInstanceBase(), m_iPlayerID(-1), m_instance(NULL), m_szName(NULL), m_bIsFirstNewStream(PR_TRUE), m_bReceivedXEmbedQuery(PR_FALSE), m_bIsInitialized(PR_FALSE), m_bReceivedScriptableInstanceQuery(PR_FALSE), m_bSentBrowserInfo(PR_FALSE), m_pBackend(pBackend){ }nsHXPlayer::~nsHXPlayer(){}NS_IMPL_ISUPPORTS2(nsHXPlayer, nsIHXPlayer, nsIClassInfo)NS_IMETHODIMP nsHXPlayer::DoCommand(const char *szCommand, PRBool *_retval){ nsresult result; char *pMsg; int nLen; *_retval = PR_FALSE; if(!m_bIsInitialized) { return NS_ERROR_FAILURE; } nLen = asprintf(&pMsg, "%s %d\n", szCommand, m_iPlayerID); result = m_pBackend->SendMessage(pMsg, nLen); free(pMsg); if(result != NS_OK) { return result; } return m_pBackend->ReadGenericResponse(_retval);}/* SetPosition is really a command that takes a position argument. As it's the only command that does this, we'll special case it here rather than expanding our IPC to handle this sort of thing.*/NS_IMETHODIMP nsHXPlayer::SetPosition(PRInt32 nPosition, PRBool *_retval){ nsresult result; char *pMsg; int nLen; *_retval = PR_FALSE; if(!m_bIsInitialized) { return NS_ERROR_FAILURE; } nLen = asprintf(&pMsg, "Seek %d, %d\n", m_iPlayerID, nPosition); result = m_pBackend->SendMessage(pMsg, nLen); free(pMsg); if(NS_FAILED(result)) { return result; } return m_pBackend->ReadGenericResponse(_retval);}NS_IMETHODIMP nsHXPlayer::GetDRMInfo(const char *szIdentifier, char **_retval){ *_retval = (char*) NPN_MemAlloc(1); *_retval[0] = '\0'; return NS_OK;}char *nsHXPlayer::GetQuotedString(const char *szString){ int nLen = 0; const char *pPos = szString; char *pQuotedPos = NULL; char *szQuotedString = NULL; while(*pPos) { if(*pPos == '\'') { nLen += 4; // '\'' } else { nLen++; } pPos++; } nLen += 3; // two ' and a \0 szQuotedString = (char*)malloc(nLen); pQuotedPos = szQuotedString; *pQuotedPos++ = '\''; pPos = szString; while(*pPos) { if(*pPos == '\'') { *pQuotedPos++ = '\''; *pQuotedPos++ = '\\'; *pQuotedPos++ = '\''; *pQuotedPos++ = '\''; } else { *pQuotedPos++ = *pPos; } pPos++; } *pQuotedPos++ = '\''; *pQuotedPos = '\0'; return szQuotedString;}nsresult nsHXPlayer::GetPlayerUINT32Prop(const char *szPropName, PRInt32 *pValue){ char *pMsg; int nLen; nsresult result; PRInt32 iReturnCode; *pValue = 0; if(!m_bIsInitialized) { return NS_ERROR_FAILURE; } nLen = asprintf(&pMsg, "GetPlayerUINT32Prop %d %s\n", m_iPlayerID, szPropName); result = m_pBackend->SendMessage(pMsg, nLen); free(pMsg); if(NS_FAILED(result)) { return result; } result = m_pBackend->ReceiveMessage(&pMsg); if(NS_FAILED(result)) { return result; } if(sscanf(pMsg, "%d, %d", &iReturnCode, pValue) != 2) { result = NS_ERROR_FAILURE; } else if(iReturnCode != NS_OK) { *pValue = 0; } free(pMsg); return result;}nsresult nsHXPlayer::GetPlayerStringProp(const char *szPropName, char **pszValue){ char *pMsg; int nLen; nsresult result; PRUint32 iReturnCode; *pszValue = 0; if(!m_bIsInitialized) { return NS_ERROR_FAILURE; } nLen = asprintf(&pMsg, "GetPlayerStringProp %d %s\n", m_iPlayerID, szPropName); result = m_pBackend->SendMessage(pMsg, nLen); free(pMsg); if(NS_FAILED(result)) { return result; } result = m_pBackend->ReceiveMessage(&pMsg); if(NS_FAILED(result)) { return result; } CStringTokenizer tokenizer(pMsg); char *szReturnCode = tokenizer.NextToken(); iReturnCode = atol(szReturnCode); free(szReturnCode); if(iReturnCode == NS_OK) { char *szValue = tokenizer.NextToken(); char *szNPNAllocedValue; // The browser will free this memory with the expectation that it was // allocated with NPN_MemAlloc. Copy over the result to a buffer allocated // this way. szNPNAllocedValue = (char*)NPN_MemAlloc(strlen(szValue) + 1); strcpy(szNPNAllocedValue, szValue); free(szValue); *pszValue = szNPNAllocedValue; } free(pMsg); return result;}nsresult nsHXPlayer::GetEntryStringProp(const char *szPropName, PRInt32 uIndex, char **pszValue){ char *pMsg; int nLen; nsresult result; PRInt32 iReturnCode; *pszValue = NULL; if(!m_bIsInitialized) { return NS_ERROR_FAILURE; } nLen = asprintf(&pMsg, "GetEntryStringProp %d '%s' %d\n", m_iPlayerID, szPropName, uIndex); result = m_pBackend->SendMessage(pMsg, nLen); free(pMsg); if(NS_FAILED(result)) { return result; } result = m_pBackend->ReceiveMessage(&pMsg); if(NS_FAILED(result)) { return result; } CStringTokenizer tokenizer(pMsg); char *szReturnCode = tokenizer.NextToken(); iReturnCode = atol(szReturnCode); free(szReturnCode); if(iReturnCode == NS_OK) { char *szValue = tokenizer.NextToken(); char *szNPNAllocedValue; // The browser will free this memory with the expectation that it was // allocated with NPN_MemAlloc. Copy over the result to a buffer allocated // this way. szNPNAllocedValue = (char*)NPN_MemAlloc(strlen(szValue) + 1); strcpy(szNPNAllocedValue, szValue); free(szValue); *pszValue = szNPNAllocedValue; } free(pMsg); return result;}nsresult nsHXPlayer::SetPlayerUINT32Prop(const char *szPropName, PRInt32 uiPropValue, PRBool *_retval){ char *pMsg; int nLen; nsresult result; *_retval = PR_FALSE; if(!m_bIsInitialized) { return NS_ERROR_FAILURE; } nLen = asprintf(&pMsg, "SetPlayerUINT32Prop %d '%s' %d\n", m_iPlayerID, szPropName, uiPropValue); result = m_pBackend->SendMessage(pMsg, nLen); free(pMsg); if(NS_FAILED(result)) { return result; } return m_pBackend->ReadGenericResponse(_retval);}nsresult nsHXPlayer::SetPlayerStringProp(const char *szPropName, const char *szValue, PRBool *retval){ char *pMsg; int nLen; nsresult result; char *szQuotedValue; *retval = PR_FALSE; if(!m_bIsInitialized) { return NS_ERROR_FAILURE; } szQuotedValue = GetQuotedString(szValue); nLen = asprintf(&pMsg, "SetPlayerStringProp %d '%s' %s\n", m_iPlayerID, szPropName, szQuotedValue); free(szQuotedValue); result = m_pBackend->SendMessage(pMsg, nLen); free(pMsg); if(NS_FAILED(result)) { return result; } return m_pBackend->ReadGenericResponse(retval);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -